Skip to content

Pay Gas Fees with ERC20 Tokens

Gas fees can be a hurdle for many users in blockchain applications. This guide will help you configure gasless transactions where the gas is paid using an ERC20 token. Choose between dynamic or fixed-rate payment strategies.

Charge an ERC20 with Dynamic Price

Step 1: Select the Contract You Want to Interact With

  • Add your collectible's smart contract.
  • Define the contract function you want to use (e.g., mint).
API
Terminal
curl https://api.openfort.io/v1/contracts \
  -u "$YOUR_SECRET_KEY:" \
  -d 'name=NFT Contract' \
  -d 'chainId=80002' \
  -d 'address=contract_address'

Dashboard Add Contract

Step 2: Set Up a Dynamic ERC20 Policy

  • Create a new policy and select the strategy charge dynamic amount of ERC20.
  • Select the ERC20 token contract and exchange rate.
  • Link the imported contract and the function you want to sponsor.
API
Terminal
curl https://api.openfort.io/v1/policies \
  -u "$YOUR_SECRET_KEY:" \
  -d 'name=My Policy' \
  -d 'chainId=80002' \
  -d 'strategy[sponsorSchema]=charge_custom_tokens' \
  -d 'strategy[tokenContract]=con_...' \
  -d 'strategy[tokenContractAmount]=1' 
Terminal
curl https://api.openfort.io/v1/policies/:id/policy_rules \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d type="contract_functions" \
  -d functionName="All functions" \
  -d contract="con_..."

Dashboard Dynamic Pricing Policy

Step 3: Create a Gasless Transaction

  • Add chainId.
  • Add the contract.
  • Add the policy.
  • Add the function you want to interact with.
Terminal
curl https://api.openfort.io/v1/transaction_intents \
  -u "$YOUR_SECRET_KEY:" \
  -d 'chainId=80002' \
  -d 'optimistic=true' \
  -d 'policy=policy_id' \
  -d 'interactions[0][contract]=contract_address' \
  -d 'interactions[0][functionName]=mint' \
  -d 'interactions[0][functionArgs][0]=sender_address_or_id'

Step 4: (Optional) Add the Account or Player

  • Add an account or player to specify the user.
Terminal
curl https://api.openfort.io/v1/transaction_intents \
  -u "$YOUR_SECRET_KEY:" \
  -d 'chainId=80002' \
  -d 'policy=policy_id' \
  -d 'account=account_id' \
  -d 'optimistic=true' \
  -d 'interactions[0][contract]=contract_address' \
  -d 'interactions[0][functionName]=mint' \
  -d 'interactions[0][functionArgs][0]=sender_address_or_id'

Charge an ERC20 with Fixed Price

Step 1: Select the Contract You Want to Interact With

  • Add your collectible's smart contract.
  • Define the contract function you want to use (e.g., mint).
API
Terminal
curl https://api.openfort.io/v1/contracts \
  -u "$YOUR_SECRET_KEY:" \
  -d 'name=NFT Contract' \
  -d 'chainId=80002' \
  -d 'address=contract_address'

Dashboard Add Contract

Step 2: Set Up a Fixed ERC20 Policy

  • Create a new policy and select the strategy charge fixed amount of ERC20.
  • Specify the ERC20 token contract and the fixed amount to charge.
  • Link the imported contract and the function you want to sponsor.
API
Terminal
curl https://api.openfort.io/v1/policies \
  -u "$YOUR_SECRET_KEY:" \
  -d 'name=Fixed Policy' \
  -d 'chainId=80002' \
  -d 'strategy[sponsorSchema]=charge_fixed_rate' \
  -d 'strategy[tokenContract]=contract_address' \
  -d 'strategy[tokenContractAmount]=1'

Dashboard Fixed Pricing Policy

Step 3: Create a Gasless Transaction

  • Add chainId.
  • Add the contract.
  • Add the policy.
  • Add the function you want to interact with.
Terminal
curl https://api.openfort.io/v1/transaction_intents \
  -u "$YOUR_SECRET_KEY:" \
  -d 'chainId=80002' \
  -d 'optimistic=true' \
  -d 'policy=pol_...' \
  -d 'interactions[0][contract]=con_...' \
  -d 'interactions[0][functionName]=mint' \
  -d 'interactions[0][functionArgs][0]=sender address or Id'

Step 4: (Optional) Add the Account or Player You're Using

  • Add account or add player
Terminal
curl https://api.openfort.io/v1/transaction_intents \
  -u "$YOUR_SECRET_KEY:" \
  -d 'chainId=80002' \
  -d 'policy=pol_...' \
  -d 'account=acc...' or 'player=pla...' \
  -d 'optimistic=true' \
  -d 'interactions[0][contract]=con_...' \
  -d 'interactions[0][functionName]=mint' \
  -d 'interactions[0][functionArgs][0]=sender address or Id'