Home

Charge a dynamic amount of ERC20 for gas payment

Learn how to charge dynamic amount of ERC20 tokens to pay for gas fees.

Charging (any) ERC-20 tokens you want as a form of payment for transactions (also supports stablecoins like USDC).

What you'll learn:#

  • How to charge ERC20 tokens to users to make a minting NFT transaction.
1

Select the contract you want to interact with

  • Add the collectible's smart contract.
  • Define the smart contract function 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 Dynamic ERC20 Policy

  • Create s new policy and select the strategy "charge dynamic amount of ERC20".
  • Select the ERC20 Token Contract and the Exchange Rate.
  • Select imported contract and the function you want to sponsor.

If you want to update the dynamic rate programmatically, contact us

command-line

_10
curl https://api.openfort.xyz/v1/policies \
_10
-u "$YOUR_SECRET_KEY:" \
_10
-d 'name=My Policy' \
_10
-d 'chainId=80002' \
_10
-d 'strategy[sponsorSchema]=charge_custom_rate' \
_10
-d 'strategy[tokenContract]=con_...' \
_10
-d 'strategy[tokenContractAmount]=1'

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

Note you can make a transaction happen without the need to have a registered user or account deployed at the time of interacting. 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 'optimistic=true' \
_10
-d 'policy=pol_...'
_10
-d 'interactions[0][contract]=con_...' \
_10
-d 'interactions[0][functionName]=mint' \
_10
-d 'interactions[0][functionArgs][0]=sender address or Id'

4

Optional: Add the Account or Player you're using

  • Add account or add player
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 'account=acc...' or 'player=pla...' \
_10
-d 'optimistic=true' \
_10
-d 'interactions[0][contract]=con_...' \
_10
-d 'interactions[0][functionName]=mint' \
_10
-d 'interactions[0][functionArgs][0]=sender address or Id'