Skip to content

Commit

Permalink
add voucher info
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenWay committed Aug 21, 2023
1 parent 7472ef7 commit f62ae6f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api/send-message.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ try {
payload: somePayload,
gasLimit: 10000000,
value: 1000,
// prepaid: true,
// account: accountId,
// if you send message with issued voucher
};
// In that case payload will be encoded using meta.types.handle.input type
let extrinsic = api.message.send(message, meta);
Expand Down Expand Up @@ -49,6 +52,9 @@ try {
payload: somePayload,
gasLimit: 10000000,
value: 1000,
// prepaid: true,
// account: accountId,
// if you send message with issued voucher
};
// In this case payload will be encoded using `meta.types.reply.input` type.
const extrinsic = api.message.sendReply(reply, meta);
Expand Down
41 changes: 41 additions & 0 deletions docs/api/vouchers.md
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.

0 comments on commit f62ae6f

Please sign in to comment.