Home

Sponsored Gas Transactions

Learn how to implement sponsored gas transactions.

With Openfort you can sponsor transactions to you users, meaning that in-game accounts don't need to have native token to execute transactions.

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.

What you'll learn:#

  • How to make a sponsored transaction to mint an NFT.
1

Select the contract you want to interact with

  • 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 a 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 gasless 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...'