This site requires Javascript to be enabled.

Grant allowance

Building a smart contract dapp that enables users to request a fee grant is a challenging task since all transactions necessitate the payment of transaction fees. However, there are several methods that can be utilized. Here are a few examples:

  • The granter can manually execute each fee grant allowance transaction using the archwayd CLI
  • Construct a deployment script containing addresses that you wish to assign a fee grant to. This script will utilize the archwayd CLI to perform the fee grant transaction for each specified address.
  • Implement a simple frontend application that verifies and validates a user's account. After confirming that they are the account owner, the application would execute a Javascript transaction with arch3.js to carry out the fee grant transaction.

Create allowance using archwayd

The archwayd CLI is a key tool for accessing the fundamental functionalities of the Archway Blockchain. To install archwayd, refer to this link. Here is an illustration of a typical transaction for creating a grant allowance:

mainnet

testnet

archwayd tx feegrant grant "${granter_addr}" "${grantee_address}" \    --chain-id "archway-1" \    --node "https://rpc.mainnet.archway.io:443" \    --spend-limit 500000000000000000aarch \    --expiration 2025-12-31T23:00:00Z \    --allowed-messages '/cosmwasm.wasm.v1.MsgExecuteContract' \    --gas auto \    --gas-prices "$(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)')" \    --gas-adjustment 1.3 \    --output json \    --yes

Let's break down a few of the components:

  • ${granter_addr}: This value represents the address of the account providing tokens to the grantee for transaction execution.
  • ${grantee_address}: This denotes the account receiving tokens, enabling it to perform transactions using these grants.
  • allowed-messages: Through the AllowedMsgAllowance type, you can limit the message type a grantee can use the grant for.
  • expiration: The deadline by which the allowance must be used or it will expire.
  • spend-limit: The maximum allowance provided to the grantee. This amount is adjusted as tokens are utilized.

Create allowance using arch3.js

This section demonstrates how to create a grant allowance using arch3.js. By following the steps outlined in this section, you'll be able to create a signing client, structure a grant allowance message, and execute the necessary transaction which will grant allowances to designated accounts. Let's dive in and explore the process of creating allowances using arch3.js.

  1. Create the signing client that will be used to execute the transaction:
const signingClient = await SigningArchwayClient.connectWithSigner(network.endpoint, wallet);
  1. The allowance message comprises three essential components: the granter, grantee, and the actual allowance. As previously mentioned, the granter is the address responsible for granting the allowance, while the grantee is the recipient who can utilize the granted allowance. The allowance component is slightly more intricate, with its structure dependent on the specific type of allowance employed.

To illustrate, let's examine the structure of a basicAllowance using the following example:

const basicAllowance = {    typeUrl: "/cosmos.feegrant.v1beta1.BasicAllowance",    value: Uint8Array.from(        BasicAllowance.encode({        spendLimit: [            {            denom: "aconst",            amount: "5000000000000000000",            },        ],        }).finish(),    ),};

Therefore, the combined message would appear as follows:

const msgGrantAllowance = {    granter: granterAddress,    grantee: granteeAddress,    allowance: basicAllowance,};const typeUrl = "/cosmos.feegrant.v1beta1.MsgGrantAllowance";const msgAny = { typeUrl, value: msgGrantAllowance };

Now, all that remains is to execute the transaction:

const broadcastResult = await signingClient.signAndBroadcast(    granterAddress,    [msgAny],    'auto',    'Fee Grant', // optional memo);

You can find a working example of this script in the dapp examples repository.

Initiate an allowance using keplr's arbitrary message

It would be great if you could enable new users to indicate their intent to utilize your dapp without requiring them to execute an on-chain transaction, especially if they don't possess the necessary tokens to complete the transaction. Wallets like Keplr and others offer a solution that allows dapps to verify account ownership off-chain. In the case of Keplr, this solution is known as an Arbitrary Message.

To implement this solution, you would need to store the user's allowance request in a centralized system or execute the transaction from a centralized backend app to grant the user an allowance once they have successfully proven ownership of their account.

The following process could be implemented:

  • The user clicks a button on your dapp to request an allowance.
  • The dapp creates an Arbitrary Message request to verify that the user is the owner of the account to which the allowance will be granted.
  • This request generates a Keplr window, prompting the user to sign the message.
  • Once the message is signed, the user's address is sent to a centralized backend system, which utilizes arch3.js to execute a fee grant allowance.
  • Upon successful completion of the allowance, the centralized system returns the results regarding the successful request and dapp displays a success message to the user.
  • The user's allowance is queried on-chain and presented and a message is shown explaining that they can now utilize the granted allowance to execute their initial transactions.