Home

Escrow Accounts

Learn how to use your dev account to escrow assets.

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.

Requisites#

To escrow assets to your dev account you need to either:

  • Support ERC-2771 transactions: The assets you want to escrow need to support ERC-2771 transactions (i.e. meta transactions). You can check the list of supported forwarder contracts.
  • Fund dev account: You need to fund your dev account with the native tokens of the network you're interacting with.

Quickstart#

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.

1. Create a dev account#

First, create your dev account in your dashboard or via API.

addDevAccount

2. 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/apikeys
_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/apikeys
_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.