Using backend wallets
Sending transactions
To execute a transaction from your backend wallet:
Node
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const transactionintents = await openfort.transactionIntents.create({
account: 'dac_...', // Your backend wallet ID
chainId: 80002,
policy: 'pol_...', // Optional: Policy ID for gas sponsorship
optimistic: true,
interactions: {
contract: 'con_....',
functionName: 'transfer',
functionArgs: ['recipient_address', 'amount']
}
})Checking transaction status
You can monitor the status of transactions through our webhook system or by querying the API:
Node
const transactionIntent = await openfort.transactionIntents.get({id:'tin_...'});
console.log(transactionIntent.status);Common Use Cases
Minting NFTs with a backend wallet
In this example, we'll use a backend wallet to mint an NFT to a player's account:
Node
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const transactionintents = await openfort.transactionIntents.create({
account: 'dac_...', // Your backend wallet ID
chainId: 80002,
policy: 'pol_...', // Policy for gas sponsorship
optimistic: true,
interactions: {
contract: 'con_....',
functionName: 'mint',
functionArgs: ['pla_...'] // Player ID receiving the NFT
}
})Transferring an ERC20 token
Here's how to transfer assets from your backend wallet to another account:
Node
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const transactionintents = await openfort.transactionIntents.create({
account: 'dac_...', // Your backend wallet ID
chainId: 80002,
policy: 'pol_...', // Policy for gas sponsorship
optimistic: true,
interactions: {
contract: 'con_....',
functionName: 'transfer',
functionArgs: ['pla_...', '1000000000000000000'] // Player ID and amount (1 token)
}
})Implementing Escrow System
This example shows how to implement an escrow system using a backend wallet:
- First, check the player's NFT inventory:
Node
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
const inventory = await openfort.inventories.getPlayerNftInventory({
player: 'pla_...',
contract: 'con_...',
})- Then, transfer the asset to the escrow wallet:
Node
const transactionintents = await openfort.transactionIntents.create({
chainId: 80002,
optimistic: false,
player: 'pla_...', // Player ID
policy: 'pol_...', // Policy for gas sponsorship
interactions: {
contract: 'con_...',
functionName: "transferFrom",
functionArgs: ['pla_...', 'dac_...', '10'], // From player to escrow wallet, token ID 10
}
});