Home

Sponsored a transaction to mint an NFT

Learn how to implement sponsored gas transactions to mint NFTs.

With Openfort you can sponsor transactions to you users, meaning that in-game wallet don't need to have native token to execute transactions, in this case, mint an NFT.

Note that the absence of a policy will enforce the user to have a native tokens in their account in order to pay for the transaction's gas fee.

1

Input the NFT (Contract)

  • Import the smart contract if you have not yet
  • Decide what function of the smart contract you want to use. In our case 'mint'.
command-line

_10
curl https://api.openfort.xyz/v1/contracts \
_10
-u "$YOUR_SECRET_KEY:" \
_10
-d 'name=NFT Contract' \
_10
-d 'chainId=80002' \
_10
-d 'address=contract address'

2

Set up the gas policy

  • Create s new policy and select the strategy "pay gas for user"
  • Select imported contract and the function you want to sponsor
command-line

_10
curl https://api.openfort.xyz/v1/policies \
_10
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
_10
-d chainId=80002 \
_10
-d name="simple sponsor" \
_10
-d "strategy[sponsorSchema]=pay_for_user"

command-line

_10
curl https://api.openfort.xyz/v1/policies/:id/policy_rules \
_10
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
_10
-d type="contract_functions" \
_10
-d functionName="All functions" \
_10
-d contract="con_..."

3

Create a transaction

  • Add chainId
  • Add contract
  • Add policy
  • Add function you want to interact with
  • Add arguments (in the case of mint, '_to' the person who receives the asset)

Note you can make a transaction happen without the need to have a registered user or account. Once you make the transaction a playerId and accountId will be created.

command-line

_10
curl https://api.openfort.xyz/v1/transaction_intents \
_10
-u "$YOUR_SECRET_KEY:" \
_10
-d 'chainId=80002' \
_10
-d 'policy=pol_...' \
_10
-d 'optimistic=true' \
_10
-d 'interactions[0][contract]=con_...' \
_10
-d 'interactions[0][functionName]=mint' \
_10
-d 'interactions[0][functionArgs][0]=0x...'

4

Optional: Add the Account or Player you're using

  • Add player
command-line

_10
curl https://api.openfort.xyz/v1/transaction_intents \
_10
-u "$YOUR_SECRET_KEY:" \
_10
-d 'chainId=80002' \
_10
-d 'player=pla...' \
_10
-d optimistic=true \
_10
-d 'interactions[0][contract]=con_...' \
_10
-d 'interactions[0][functionName]=mint' \
_10
-d 'interactions[0][functionArgs][0]=pla...'