How to onboard users and make a sponsored transaction
The following document was contributed by @joalavedra. Give them a shoutout if you find it useful!
Openfort is an open-source alternative to wallet infrastructure solutions. The core offerings—Openfort Kit, Invisible Wallet, and Cross-app Wallet - enable rapid integration of wallet functionality, intuitive onboarding, and flexible user journeys for any application or ecosystem.
Openfort Kit
Openfort Kit is a developer toolkit that streamlines the integration of wallet authentication and connectivity into any web application. It provides:
- Plug-and-play UI Components: Prebuilt, customizable authentication and wallet connection flows that can be deployed in minutes, not weeks, with support for major authentication providers and wallet connector
- Developer Experience: TypeScript-ready, ecosystem-standard libraries (wagmi, viem), and easy integration with frameworks like React, Next.js, and Create React App.
- Full Customization: Predesigned themes or the ability to fully tailor the UI to match your brand.
Invisible Wallet
Invisible Wallet enables applications to onboard users without requiring them to interact directly with traditional wallet interfaces. Features include:
- Embedded Non-custodial Signer: Secure, self-custodied wallet creation and signing for users, with no need for browser extensions or external apps.
- Fundign Support: Users can onramp their newly created wallets with traditional methods or depositing crypto.
- Key Export: Users can always export private keys, allowing them to take the wallet with them.
Cross-app Wallet
The Cross-app Wallet empowers ecosystems and platforms to offer branded, interoperable wallets that work across multiple apps and services. Key capabilities:
- Ecosystem SDK: Build your own wallet SDK that can be integrated across your suite of apps, ensuring users have a consistent identity and asset management experience everywhere.
- No App or Extension Required: Users can create and use wallets instantly via iFrames or embedded flows, compatible with any EVM chain.
- Modern Standards: Supports the latest Ethereum standards (EIP-1193, 6963, 7702, 4337, and more) for broad compatibility and future-proofing.
How to implement a sponsored transaction on Arbitrum using Openfort
With Openfort, you can sponsor transactions for your users, meaning that in-game wallets don't need native tokens to execute transactions, such as minting an NFT. This guide will walk you through the process of implementing a gasless transaction to mint an NFT on Arbitrum.
1. Import the NFT Contract
First, you need to import the smart contract you'll be interacting with. In this case, we'll use an NFT contract with a mint
function.
curl https://api.openfort.xyz/v1/contracts \
-u "$YOUR_SECRET_KEY:" \
-d 'name=NFT Contract' \
-d 'chainId=42161' \
-d 'address=YOUR_CONTRACT_ADDRESS'
Replace YOUR_CONTRACT_ADDRESS
with the address of your NFT contract on Arbitrum.
2. Set up the Gas Policy
Create a new policy to sponsor gas fees for users:
curl https://api.openfort.xyz/v1/policies \
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
-d chainId=42161 \
-d name="Arbitrum NFT Sponsor" \
-d "strategy[sponsorSchema]=pay_for_user"
Then, add a policy rule for the NFT contract:
curl https://api.openfort.xyz/v1/policies/:id/policy_rules \
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
-d type="contract_functions" \
-d functionName="mint" \
-d contract="con_..."
Replace :id
with the policy ID returned from the previous step, and con_...
with your contract ID.
3. Create a gasless transaction
Now, let's create a transaction to mint an NFT without the user paying for gas:
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const policyId = 'pol_...'; // Your policy ID from step 2
const transactionIntent = await openfort.transactionIntents.create({
chainId: 42161, // Arbitrum One
policy: policyId,
optimistic: true,
interactions: {
contract: 'con_....', // Your NFT contract ID
functionName: 'mint',
functionArgs: ['0x...'], // Address to receive the NFT
},
});
4. Optional: specify the player
If you want to associate the transaction with a specific player:
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const playerId = 'pla_...'; // Your player ID
const policyId = 'pol_...'; // Your policy ID from step 2
const transactionIntent = await openfort.transactionIntents.create({
player: playerId,
chainId: 42161, // Arbitrum One
policy: policyId,
optimistic: true,
interactions: {
contract: 'con_....', // Your NFT contract ID
functionName: 'mint',
functionArgs: [playerId], // Minting to the player's address
},
});
By following these steps, you've created a gasless transaction on Arbitrum using Openfort. The user can now mint an NFT without needing to hold ETH
for gas fees. Remember to handle the response from the transactionIntents.create
call in your application to provide feedback to the user about the minting process.
For a more detailed tutorial, please refer to the Openfort Quick Start Guide.
Connect with Openfort
Need further assistance? Reach out to Openfort for support and stay updated:
- Visit Openfort's official website at openfort.io
- Read the Documentation
- Check out Openfort on GitHub