-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
sidebar_position: 7 | ||
sidebar_label: Vouchers | ||
--- | ||
|
||
# Gas vouchers | ||
|
||
Vouchers, issued by any actor empower users with gas-free interactions, enabling them to send messages to specific programs seamlessly. | ||
|
||
Use `api.voucher.issue` method to issue a new voucher for a user to be used to pay for sending messages to `program_id` program. | ||
|
||
```javascript | ||
import { VoucherIssued } from '@gear-js/api'; | ||
|
||
const programId = '0x..'; | ||
const account = '0x...'; | ||
const tx = api.voucher.issue(account, programId, 10000); | ||
tx.signAndSend(account, (events) => { | ||
const voucherIssuedEvent = events.events.filter(({event: {method}}) => method === 'VoucherIssued') as VoucherIssued; | ||
console.log(voucherIssuedEvent.toJSON()); | ||
}) | ||
``` | ||
|
||
Use `api.voucher.exists` method to check that the voucher exists for a particular user and program: | ||
|
||
```javascript | ||
const voucherExists = await api.voucher.exists(programId, accountId); | ||
``` | ||
|
||
To send message with voucher set `prepaid` flag to `true` in the first argument of `api.message.send` and `api.message.sendReply` methods. Also it's good to specify account ID that is used to send the extrinsic to check whether the voucher exists or not. | ||
|
||
```javascript | ||
let massage = await api.message.send({ | ||
destination: destination, | ||
payload: somePayload, | ||
gasLimit: 10000000, | ||
value: 1000, | ||
prepaid: true, | ||
account: accountId, | ||
}, meta); | ||
``` |
Empty file.