diff --git a/docs/api/send-message.mdx b/docs/api/send-message.mdx index feea9d6a9..8dff23c97 100644 --- a/docs/api/send-message.mdx +++ b/docs/api/send-message.mdx @@ -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); @@ -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); diff --git a/docs/api/vouchers.md b/docs/api/vouchers.md new file mode 100644 index 000000000..50d9e0ff9 --- /dev/null +++ b/docs/api/vouchers.md @@ -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); +``` \ No newline at end of file diff --git a/docs/developing-contracts/payless-transactions.md b/docs/developing-contracts/payless-transactions.md new file mode 100644 index 000000000..e69de29bb