Skip to content

Using backend wallets

Create wallet

Backend wallets can be created through our dashboard or API. You can either create a new wallet or add an existing one.

Using the Dashboard

Navigate to the Openfort dashboard and create a new developer account.

Using the API

You can create or add backend wallets through our API:

Node
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(YOUR_SECRET_KEY);
 
const settings = await openfort.settings.createDeveloperAccount()

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.retrieve('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 Assets

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:

  1. 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_...',
})
  1. 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
  }
});