Skip to content

Commit

Permalink
add voucher info (#529)
Browse files Browse the repository at this point in the history
Co-authored-by: AndrePanin <[email protected]>
  • Loading branch information
EugenWay and AndrePanin authored Aug 21, 2023
1 parent 7472ef7 commit bf3f6b1
Show file tree
Hide file tree
Showing 3 changed files with 82 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);
```
35 changes: 35 additions & 0 deletions docs/gear/distinctive-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ Perhaps most interestingly, gas reservation allows a program to send a message t

This opens up a wide range of possibilities for the implementation of functional logic related to **continuing messaging automation** in smart contracts. Delayed messages are similar to cron jobs, which cannot be implemented in smart contracts on other blockchain platforms without the use of external resources. The remarkable advantage of this solution is that it eliminates the need for centralized components in dApps, ensuring they function **completely on-chain** and are fully decentralized and autonomous.

## Payless Transactions

Gear Protocol's Payless Transactions feature introduces a groundbreaking concept to the world of Web3, revolutionizing communication within Gear-powered networks and increasing the adoption of decentralized applications, making their ease of use closer to Web2 services and applications.

This innovative feature empowers actors to issue vouchers that enable specific users to send messages to designated programs without incurring gas fees. This paradigm-shifting approach fosters a sponsorship-like environment for users, transforming the way interactions take place in the Web3 ecosystem.

### Understanding Payless Transactions

At the core of the Payless Transactions feature lies the concept of vouchers. These vouchers are crafted to grant users the ability to send messages to specific programs within the network, all without the burden of gas fees. Each voucher comes with a predetermined allocation of gas, empowering users to initiate interactions without worrying about transaction costs.

### How Payless Transactions Work

1. **Voucher Issuance**: Actors within the Vara Network can issue vouchers, creating a sponsorship mechanism for users. These vouchers are tied to specific programs and include a designated gas allocation.

2. **Message Sending**: Holders of valid vouchers can use them to send messages to the designated program. These messages can include instructions or data, enriching interactions within the network.

3. **Gas-Free Interactions**: Users who has valid vouchers can enjoy gas-free interactions when sending messages. The allocated gas from the voucher covers the associated transaction costs.

### Benefits of Payless Transactions

- Encourages user participation by eliminating the gas fee barrier
- Reduced сomplexity for dApps adoption
- Fostering a more inclusive and vibrant network
- More accessible and user-friendly (Web2-like approach)

### How does it work?

Learn how to create and use vouchers in [this article](/docs/api/vouchers.md).

## Use cases

For instance, let's consider some use case examples that become achievable:
Expand All @@ -42,6 +71,12 @@ Overall, the ability to update NFTs dynamically opens up a wide range of possibi

### Gaming

Everyone knows that the most successful games are those that are exciting, that you play with pleasure.

The success of such games depends on the right game mechanics established by the developers. The Gear Protocol offers a tool for developing such games and running them on a decentralized network, like [Vara](https://vara-network.io/). Features such as [delayed messages](/developing-contracts/delayed-messages.md), [payless transactions](/docs/api/vouchers.md), and [gas reservation](/developing-contracts/gas-reservation.md) become essential tools for developers aiming to create successful games on the Gear decentralized network.

Here are a few of the many examples where such functionality would be useful:

Tamagotchi is a classic digital pet game where players must care for a virtual creature by providing it food, attention, and other forms of care. As a dynamic NFT, a Tamagotchi can change its appearance based on its properties (such as hunger, fatigue, or happiness) and can notify the user when it needs to be fed or played with. The user can feed the NFT with gas, which is used to send delayed messages that are required to update the Tamagotchi's state.

"Game strategies battle" is a game in which several programs compete with each other using different algorithms or strategies. The game can be based on a variety of classic games, such as checkers, tic-tac-toe, races, or Monopoly. Each participant creates a smart contract with their own game strategy and uploads it to the blockchain. The programs then play against each other until someone wins or the gas runs out. If the gas runs out, one of the participants can continue the game by sending a message with more gas. This allows the game to continue indefinitely, with the most effective strategy ultimately emerging as the winner.
Expand Down

0 comments on commit bf3f6b1

Please sign in to comment.