Management API Reference

Server

Backend wallets

Backend wallets, are externally-owned accounts to be used internally to manage the game flows and experience.

They can execute game logic like escrow for competition or sending a minted asset to a player after winning a competition.

Please refer to our guide on how to create backend wallets to learn how to create them through your Openfort dashboard.

Minting#

Designed for situations where controlled minting is necessary, typically governed by a contract allowing only certain addresses to mint new assets.

You might have contracts deployed that need to be minted on-demand, (we recommend having a pre-defined allowlist of addresses that are able to mint assets for the contract).

These accounts are included in a contract's allowlist, which specifies who can mint assets. To set up a minting account, a dev account is created, and its address is added to this allowlist. This process ensures that only authorized dev accounts can initiate the minting process.

Minting an asset#

To minting an asset create a new transactionIntent using the dev account.

To sponsor the transaction, the contract NFT supports ERC-2771 transactions. If not, you need to fund the dev account with the native tokens of the network you're interacting with.

Therefore, we set a policy with a policy rule account_functions that allows the dev account interactions. Learn how to create a policy sponsor.

If you would like to mint an asset to a player's account, do the following:

server.ts

_21
// Set your secret key. Remember to switch to your live secret key in production.
_21
// See your keys here: https://dashboard.openfort.xyz/developers/api-keys
_21
const Openfort = require('@openfort/openfort-node').default;
_21
const openfort = new Openfort(YOUR_SECRET_KEY);
_21
_21
const devAccount = 'dac_...';
_21
const playerId = 'pla_...';
_21
const policyId = 'pol_...';
_21
_21
const transactionintents = await openfort.transactionIntents.create({
_21
account: devAccount,
_21
chainId: 80002,
_21
policy: policyId,
_21
optimistic: true,
_21
interactions:{
_21
contract: 'con_....',
_21
// The function name and arguments depend on the contract you're interacting with
_21
functionName: 'mint',
_21
functionArgs: [playerId]
_21
}
_21
})

Treasury#

Using your dev account to manage pre-minted on-chain assets. Ideal for games requiring a fixed set of pre-minted assets.

A Treasury account operates as a standard EOA, authorized via an API key. After integrating your game's pre-minted assets into our contracts, you transfer these assets to the treasury account's address. This setup enables you to redistribute the assets from the Treasury to other accounts within your game.

If pre-minted assets get distributed in batches, you might want to create a treasury account per batch - or periodically send assets to the treasury's address - managing these accounts is up to you.

Transferring an asset#

Once you have a dev account, you can transfer assets to it.

To sponsor the transaction, the contract supports ERC-2771 transactions. If not, you need to fund the dev account with the native tokens of the network you're interacting with.

Therefore, we set a policy with a policy rule account_functions that allows the dev account interactions. Learn how to create a policy sponsor.

You're all set, you can now transfer assets to the player's account.

server.ts

_22
// Set your secret key. Remember to switch to your live secret key in production.
_22
// See your keys here: https://dashboard.openfort.xyz/developers/api-keys
_22
const Openfort = require('@openfort/openfort-node').default;
_22
const openfort = new Openfort(YOUR_SECRET_KEY);
_22
_22
const devAccount = 'dac_...';
_22
const playerId = 'pla_...';
_22
const policyId = 'pol_...';
_22
const amount = '1000000000000000000'; // 1 token
_22
_22
const transactionintents = await openfort.transactionIntents.create({
_22
account: devAccount,
_22
chainId: 80002,
_22
policy: policyId,
_22
optimistic: true,
_22
interactions:{
_22
contract: 'con_....',
_22
// The function name and arguments are specific to the contract you're interacting with
_22
functionName: 'transfer',
_22
functionArgs: [playerId, amount]
_22
}
_22
})

Escrow#

Using your dev account to escrow assets where players put their assets on the line. For example, when players participate in PvP-match.

These accounts ensure fair play by holding players' assets during a game, preventing dishonest tactics like disconnecting or transferring assets when facing a likely loss.

1. Creation: When a player, say Player A, initiates a PvP match, the game developer creates a escrow account. This dev accounts, distinct from any user account, holds assets wagered by the players. 2. Asset Transfer: Players, A and B, choose an asset each for the match. Through the game's interface, they transfer these assets to the escrow account. Once transferred, the assets are out of the players' control. 3. Validation: The game system verifies the transfer by checking the assets in the escrow account. A simple count of the assets confirms whether the match is set to begin.

Asset transfers to Escrow account#

Now, let's assume two players are matched and both need to decide what asset (let's say an NFT) they want to deposit in the escrow account to start the game.

To do that, they both need to select the tokenId from the NFT they want to escrow.

server.ts

_10
// Set your secret key. Remember to switch to your live secret key in production.
_10
// See your keys here: https://dashboard.openfort.xyz/developers/api-keys
_10
const Openfort = require('@openfort/openfort-node').default;
_10
const openfort = new Openfort(YOUR_SECRET_KEY);
_10
_10
const inventory = await openfort.inventories.getPlayerNftInventory({
_10
player: 'pla_...',
_10
contract: 'con_...',
_10
})

Once both players have chosen their assets, move them to the escrow account. You will need to do this for each of the players with the asset they want to escrow: Bear in mind, here we're using a policy sponsor to pay for the gas fees. Learn how to create a policy sponsor.

server.ts

_22
// Set your secret key. Remember to switch to your live secret key in production.
_22
// See your keys here: https://dashboard.openfort.xyz/developers/api-keys
_22
const Openfort = require('@openfort/openfort-node').default;
_22
const openfort = new Openfort(YOUR_SECRET_KEY);
_22
_22
const playerId = 'pla_...';
_22
const receiver = 'dac_...';
_22
const tokenId = '10';
_22
const policyId = 'pol_...';
_22
_22
const transactionintents = await openfort.transactionIntents.create({
_22
chainId: 80002,
_22
optimistic: false,
_22
player: playerId,
_22
policy: policyId,
_22
interactions: {
_22
contract: 'con...',
_22
// The exact function name and arguments depend on the contract you're interacting with
_22
functionName: "transferFrom",
_22
functionArgs: [playerId, receiver, tokenId],
_22
}
_22
});

The assets are now in the escrow account and the game can start.

After the game finishes, you can transfer the assets back to the players' accounts using the same process changing the receiver and playerId parameters.

To sponsor the transaction, the contract supports ERC-2771 transactions. If not, you need to fund the dev account with the native tokens of the network you're interacting with.

Therefore, we set a policy with a policy rule account_functions that allows the dev account interactions.