Building a React dApp to Interact with Token Factory Tokens
This guide walks through creating a React-based decentralized application (app) that interacts with a token created using the XION Token Factory. This app will:
Authenticate users with a Meta Account that would have received a token created via the Token Factory. See the following guide on how to create your token.
Display the token balance for the logged-in user
Enable the logged in user to send tokens to another address
Setting Up the Project
Initialize a New Next.js Project
Run the following command to create a new Next.js project configured with TypeScript, ESLint, and Tailwind CSS:
npx [email protected] xion-token-dapp \
--use-npm --ts --eslint --tailwind --app --src-dir --import-alias "@/*"Navigate to the Project Directory
cd xion-token-dappInstall Dependencies
Install the Abstraxion SDK:
npm install @burnt-labs/abstraxionStart the Development Server
Open http://localhost:3000 in your browser to view the default Next.js page.
Deploying a Treasury Contract for Gasless Transactions
Before integrating the Abstraxion SDK into the application, we first need to deploy a Treasury Contract. This contract facilitates gasless transactions by executing fee grants on behalf of users.
Steps to Deploy a Treasury Contract
Login to the XION Developer Portal.
Click on "New Treasury" to create a new treasury contract.
Select the appropriate configuration based on your use case. The following "Fee Grant" and "Grant Config" images gives a recommended configuration that works for this particular use case:
Fee Grant

Enter a "Description" in the description field. This will reflect the intended purpose of the request.
In the "Allowance Type" field, enter
"/cosmwasm.feegrant.v1beta1.BasicAllowance".You can apply a "Spend Limit" if you wish, which will be applied to each user .
Click the "Save" button to apply the configuration.
Grant Config

For this example the "Type URL" would be
"/cosmos.bank.v1beta1.MsgSend"as this would allow for the app the send tokens on behalf of the user.Enter a "Description" in the description field. This will reflect the intended purpose of the request. This description will be displayed to users when they click "Allow" after connecting their account.
In the "Authorization Type" field, select
"/cosmos.authz.v1beta1.GenericAuthorization".Then click the "Save" button which generates the "Treasury Instance Preview"
Treasury Instance Preview

Once the preview is to your liking click the "Create" button to create the Treasury contract.
Configuring Abstraxion for Authentication
To enable account abstraction and gasless transactions, integrate the Abstraxion provider into your application.
Configure the Abstraxion Provider
Replace the contents of src/app/layout.tsx with the following:
Replace YOUR_TREASURY_CONTRACT_ADDRESS_HERE with the actual treasury contract address.
Bringing it Together
Replace the contents of src/app/page.tsx with the following code:
Replace TOKEN_DENOM with the actual Token Factory token denomination. Also, replace DENOM_DISPLAY_NAME with the name of the token you want to display next to the balance.
The sections below will provide a walkthrough of the code above.
Token Configuration
Defines the Token Factory token’s denomination that will be queried and transferred.
DENOM_DISPLAY_NAMEis used for a more readable display instead of the full denom.
Fetching Token Balance
Queries the XION blockchain for the user’s Token Factory token balance.
Uses the Abstraxion Client (
queryClient.getBalance()).Updates the
balancestate with the retrieved amount.
Sending Tokens
Uses
sendTokens()to send tokens from the logged-in user’s address to the recipient.Uses a gas adjustment of
1.5for reliability.If successful, stores transaction details (
transactionHash,height).Calls
getTokenBalance()to update the UI after sending tokens.
UI Rendering
Displaying User’s Address
Shows the logged-in user's address for easy reference.
Displaying Token Balance
Displays the user’s current Token Factory balance.
Token Transfer Form
Allows the user to enter a recipient address and token amount.
Calls
handleSend()when "Send Tokens" is clicked.
Displaying Transaction Details After Sending Tokens
Displays transaction details after sending tokens.
Provides a block explorer link for verification.
A Quick Walkthrough
The following steps outline how to use the app.
Log into the app
The first step after accessing the app at http://localhost:3000/ is to log in by clicking the CONNECT button.

Get Token Balance
After logging in, you will see your Meta Account address. You need to send some of your custom Token Factory tokens to that address.
Once the tokens have been sent, click the Get Token Balance button to retrieve the updated balance.

Sending Tokens
To send tokens to another address:
Enter a valid address in the Recipient Address text box.
Enter the amount to send in the Amount text box.
Click the Send Tokens button.

After submitting the transaction, you will see the transaction hash, the block height at which the transaction was executed, and a URL to view the transaction details in the block explorer.

You now have a functional React app that:
Authenticates users via Meta Accounts
Fetches and displays Token Factory token balance
Enables users to send tokens to another address
Last updated
Was this helpful?