XION
DiscordGithub
  • Welcome to XION
  • XION'S Core
    • Concepts
      • Generalized Chain Abstraction
      • Intro to Account Abstraction
      • XION's Meta Accounts
      • Meta Accounts Design
      • Architecture & Tech Glossary
      • Use Cases
  • developers
    • Xion Quick Start
      • Zero to Dapp in 5 Minutes
        • Launch a User Map Dapp on XION in 5 Minutes
        • React Native Mobile Dapp on XION in 5 Minutes
    • Mobile dapp Development on XION
      • Set up your XION Mobile Development Environment
      • Create Mobile Dapp and Integrate Meta Account Authentication
    • Getting Started (Advanced)
      • Set Up Local Environment
        • Setting up your Local Smart Contract Development Environment for XION
          • Setting up your XION Smart Contract Development Environment on Windows (WSL2 + Ubuntu)
        • Set Up an Integrated Development Environment (IDE)
        • Interacting with Xion Chain using Xion Daemon
      • Your First Contract
        • Deploying Your First Smart Contract on XION
      • Gasless UX & Permission Grants
        • Enabling Gasless Transactions with Treasury Contracts
      • Dapp Development
        • Account Abstraction with Gasless Transactions
        • Interact with XION via your Backend Service
    • Re-using Existing Contracts
      • Deployed Contracts on XION
      • Non-Fungible Tokens (NFTs)
      • Fungible Tokens
      • Marketplace
      • Multisig
      • Proxy Contracts
      • Membership Management
    • Web3 for Web2 Developers
      • Web2 vs Web3 App Architecture: A Comparison
      • Misconceptions and Misapplied Web2 Patterns
      • Recommended Architecture for Dapps on XION
    • Building for Mainnet
      • Xion Testnet: Your Development Playground
      • Building with Audited & Battle-Tested Contracts
      • Community Engagement: Building Support for Your dApp
      • Deploying to Xion Mainnet
        • Smart Contract Audits: Process, Costs & Support
        • Governance Process to Deploying Smart Contracts to Mainnet
    • Learn & Build
      • Token Factory
        • Creating, Minting, and Interacting with a Token Factory Token
        • Building a React dApp to Interact with Token Factory Tokens
        • Integrating a Token Factory Token in a Smart Contract
      • Websockets
        • WebSockets with Xion: Real-Time Communication
      • Mobile Development
        • Building a React Native Mobile App with Abstraxion (Xion.js)
      • Oracles
        • Creating a Smart Contract with Pyth Oracle Integration
      • Indexers: Optimized Data Retrieval
        • SubQuery
      • Use Cases
        • Building a Per-User Data Storage Dapp
    • Reference and Resources
      • Requesting XION Testnet Tokens
      • Public Endpoints & Resources
      • Block Explorers
      • Governance
        • Deploying Smart Contracts to Mainnet
      • Developer Tools: Abstract
      • IBC Denoms on XION Networks
      • Frequently Asked Questions
      • XION Token Contract Addresses on EVM Chains
  • Nodes & Validators
    • Run a Node
      • System Specifications
      • Build the Xion Daemon
      • Download the Xion Daemon
      • Configure the Xion Daemon
        • app.toml
        • client.toml
        • config.toml
      • Join the XION Network
        • xion-testnet-1
      • Confirm node is running
    • Become a Validator
      • Initial Setup
      • Obtain a XION Wallet Address
      • Obtain Funds
        • Testnet
      • Create Validator
    • IBC Relayers and Tokens
  • Others
    • Resources
Powered by GitBook
On this page
  • Understanding Fee Grants and Authorizations
  • Fee Grants
  • Authorizations (Authz)
  • Developer Portal
  • The Dashboard
  • Creating a Treasury Contract
  • Fee Grant
  • Grant Configuration
  • Editing a Treasury Contract
  • Withdraw Funds
  • Update Params
  • Update Fee Config
  • Update and Add Grant Configs
  • Delete a Grant Configs
  • Client-Side Implementation (React App)

Was this helpful?

Edit on GitHub
  1. developers
  2. Getting Started (Advanced)
  3. Gasless UX & Permission Grants

Enabling Gasless Transactions with Treasury Contracts

Deploying your Treasury Contract for Delegated Authorization and Gasless Transactions

Treasury contracts introduce an OAuth-like authentication flow fully on-chain, allowing developers to create intricate allowance systems that enable delegated authorization. This allows an account (the granter — the end user) to grant permission to another account (the grantee — the treasury contract) to execute specific types of transactions on their behalf. These contracts also enable a gasless experience for end users via fee grants. This guide walks you through using the developer portal to deploy your dApp’s first treasury contract.

Each treasury contract deployment is designed for a single dApp. Think of it like setting up OAuth for your application, where your dApp requests access to data from the XION chain on behalf of the user — without accessing any private information.

Understanding Fee Grants and Authorizations

Treasury contracts leverage two key modules to provide their core functionality: Fee Grants and Authz (Authorization). These modules enable gasless transactions and delegated authorization, enhancing the user experience.

Fee Grants

The Fee Grant module allows an account (granter) to cover gas fees for another account (grantee), making transactions gasless for the end user. This feature is particularly useful for onboarding users, as it removes the need for them to hold native tokens to pay for transaction fees.

How Fee Grants Work?

  1. The treasury contract holds a balance of XION tokens to cover gas fees.

  2. The contract grants fee sponsorship for specific transactions.

  3. The user (grantee) submits a transaction, and the treasury contract pays the gas fee automatically.

Key Benefits of Fee Grants

  • Frictionless onboarding – Users can interact with the dApp immediately without needing XION tokens.

  • Better user experience – Reduces complexity and improves adoption for non-crypto-native users.

  • Controlled sponsorship – dApps can define limits on gas fee coverage.

Authorizations (Authz)

The Authz module enables delegated authorization, allowing one account (granter) to grant another account (grantee) permission to execute specific transactions on its behalf.

How Authz Works in Treasury Contracts?

  • The user acts as the granter, granting permission to the treasury contract (grantee) to execute transactions on their behalf.

  • The treasury contract defines allowed actions, for exmple token transfers.

  • Users approve the treasury contract to execute these actions on their behalf.

  • The dApp allows users to trigger transactions, which the treasury contract then executes on their behalf.

Key Benefits of Authz

  • Security and control – Users define exactly which actions the treasury contract can perform.

  • Automation – Transactions can be executed without requiring constant user approval.

  • Efficiency – Reduces manual signing and streamlines dApp interactions.

By combining Fee Grants and Authz, Treasury Contracts offer a seamless and user-friendly blockchain experience, eliminating gas fees while maintaining security and control over transaction execution.

Developer Portal

We have developed a Developer Portal to provide resources that developers can leverage within their dApps. The first feature available is the creation and management of Treasury Contracts. You can access the Developer Portal using the following links:

To perform any actions, you must log in to the portal. After logging in, you will be automatically redirected to the Dashboard, where you can create and manage your deployed Treasury Contracts.

The Dashboard

The Dashboard displays all your deployed Treasury Contracts. Once you create a contract, it will appear in your list of active deployments.

Important Note:

  • Contract details are stored in your browser's local storage.

  • Switching browsers or devices will not retain your deployed contract list.

Creating a Treasury Contract

To create a new Treasury Contract, follow these steps:

  1. Click the "New treasury" button located at the top right corner of the Dashboard.

  2. A setup screen will appear, prompting you to configure the contract settings.

You must complete the required fields for each module:

  • Fee Grant: At least one fee grant is required to enable gasless transactions.

  • Grant Config: At least one authorization grant must be set up to define transaction permissions.

In the next sections, we'll go through each module in more detail.

Fee Grant

The Fee Grant section allows you to set up a mechanism to cover gas fees for user interactions within your dApp. There are three types of fee allowances available:

1. Basic Allowance (/cosmos.feegrant.v1beta1.BasicAllowance)

  • Defines a fixed spend limit per transaction.

  • Ideal for simple fee grants where users have a predefined gas budget.

2. Periodic Allowance (/cosmos.feegrant.v1beta1.PeriodicAllowance)

  • Allows users to access the grant at set intervals.

  • You can specify:

    • Period duration (time users must wait before reusing the grant).

    • Spend limit per period to control gas consumption.

3. Allowed Message Allowance (/cosmos.feegrant.v1beta1.AllowedMsgAllowance)

  • Restricts the fee grant to cover only specific transaction types.

  • You can apply either a Basic Allowance or Periodic Allowance to the specified transaction type.

Configuring the Fee Grant

  1. Enter a description explaining what the grant will cover.

  2. Select the allowance type (Basic, Periodic, or Allowed Message Allowance).

  3. Fill in the required fields based on the selected allowance type.

  4. Click "Save" to finalize and store the Fee Grant configuration.

Once saved, the Fee Grant settings will be applied, which you can see in the "Treasury Instance Preview":

Grant Configuration

This section allows you to define transaction permissions (allowances) that users must agree to before your dApp can execute actions on their behalf.

Setting Up Authorization

  1. Enter a Description

    • Provide a clear and concise description explaining the purpose of the authorization.

    • This description will be shown to users when they click "Allow" after connecting their account.

  2. Select a Type URL

    • The Type URL determines the kind of transactions your dApp will be authorized to perform.

    • Example: Selecting "/cosmwasm.wasm.v1.MsgExecuteContract" allows your dApp to execute transactions on a smart contract on behalf of the user.

      • Define Contract Execution Authorization

        • Select the authorization type (currently, "/cosmwasm.wasm.v1.ContractExecutionAuthorization" is the only option).

        • Enter the contract address that your dApp will interact with on behalf of the user.

      • Set Transaction Limits (Optional)

        • You can impose restrictions on:

          • Total number of allowed contract calls.

          • Maximum fund spending limit.

          • Both call count and fund spending limits for added security.

      • Configure Message Filters

        • Allow all messages – Grants permission to execute any message within the contract.

        • Accepted message keys – Specify which message types can be executed.

        • Accepted raw messages – Define precise message structures that can be processed.

Customization and Editing

  • All configurations generated here can be edited and customized as needed.

  • Ensure that keys are always in snake_case (e.g., max_spend_limit) and not camelCase (maxSpendLimit).

Once configured, these settings define how your Treasury Contract interacts with users and enforces controlled transaction execution.

Once you've entered all the required information, click the "Add contract grant" button.

Important Notes:

  • You can add multiple Grant Configs, allowing you to define different permissions for various interactions.

  • After adding all the necessary grant configurations, click the "Create" button to finalize and deploy the Treasury Contract.

Once created, the contract will appear on the Dashboard.

Fund the Treasury Contract: Transfer XION tokens to the contract to ensure it can cover gas fees for fee grants.

Editing a Treasury Contract

Once a Treasury contract is created, it will appear in the Dashboard. To edit it, simply click on the contract from the list, which will open a management screen.

Withdraw Funds

To withdraw any funds sent to the Treasury contract:

  1. Click the "Withdraw Funds" button.

  2. A withdrawal screen will appear.

  3. Enter the amount to withdraw which transfers funds from the Treasury contract back to the admin account.

Update Params

To modify the parameters:

  1. Click the "Update Params" button.

  2. A configuration screen will load, allowing you to adjust relevant params.

Update Fee Config

To edit the fee config:

  1. Click the "Edit" button under the Fee Config section.

  2. This will open a screen where you can adjust the fee parameters.

Update and Add Grant Configs

To modify existing grant configurations or add new ones, click the arrow next to the listed permission.

A screen will open where you can edit the configuration:

If creating a new grant:

  • Select a new Type URL.

  • Enter the required field data.

  • Click "Save" to create a new Grant Config.

Each Grant Config will be displayed under the Permissions section in the Dashboard:

Delete a Grant Configs

If you need to remove a grant configuration from your treasury contract, you can easily do so through the grant config listing interface. The process involves selecting the grant you wish to delete, confirming the action.

To delete an existing grant configurations click the trash bin icon on the right of the listed permission.

Confirm Deletion

After clicking the trash bin icon, a popup window will appear with the title "Remove grant config". The body of the popup will display the following message: "Are you sure you want to remove the <type url of config> grant config?"

  • Cancel: If you change your mind and do not want to delete the grant config, simply click the Cancel button to close the popup without making any changes.

  • Confirm: If you're sure you want to delete the grant config, click the Confirm button.

After successful deletion, the page will reload and display a success message confirming that the grant configuration has been removed.

Client-Side Implementation (React App)

You’ll need to configure the AbstraxionProvider by setting the Treasury contract in the config:

const treasuryConfig = {
	treasury: `CONTRACT_ADDRESS`,
	// optional (only for mainnet)
	// rpcUrl: ``,
	// restUrl: ``
}


export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <AbstraxionProvider
          config={treasuryConfig}>
          {children}
        </AbstraxionProvider>
      </body>
    </html>
  )
}

This configuration also determines the redirect URL users see after clicking Connect and before clicking Allow (as shown in the screenshot below).

While connecting their accounts, users will see a list of Allowances — this message is set during the Treasury contract’s creation by the developer while configuring the grant settings.

Once the user clicks Allow, the dApp:

  1. Creates Grant permissions

  2. Deploys a Fee Grant on behalf of the user.

Whenever your app executes a transaction using .execute, make sure the granter in the fee configuration (4th parameter) is set to the Treasury contract’s address:

If you modify the app to use Treasury contracts, ensure that all users log out and reconnect to apply the new settings.

return client.execute(
    sender,
    contract,
    msg,
    {
      amount: [{ amount: "1", denom: "uxion" }],
      gas: "500000",
      granter: TREASURY.treasury
    },
    "",
    []
  );
PreviousGasless UX & Permission GrantsNextDapp Development

Last updated 19 days ago

Was this helpful?

Testnet:

Mainnet:

To integrate gasless transactions and delegated authorizations using a Treasury contract in your dApp, follow this .

If you have any questions or encounter issues, feel free to ask in our or on in our .

https://dev.testnet2.burnt.com
https://dev.burnt.com
full guide
Telegram Developer Group
Discord
Dev Chat channel