Skip to content

Gas Policy Strategies & Rules

Gas Policy Strategies

Gas policies offer three distinct strategies for handling transaction fees:

1. Sponsored Transactions

Developers cover all gas fees, removing the need for users to hold native tokens.

Dashboard

PolicyERC20Payment

API

curl https://api.openfort.io/v1/policies/ \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d chainId=80002 \
  -d name="Sponsored Policy" \
  -d "strategy[sponsorSchema]=pay_for_user"

2. Dynamic ERC20 Payment

Users pay gas fees using ERC20 tokens at a dynamic exchange rate.

Dashboard

PolicyERC20Payment

API

curl https://api.openfort.io/v1/policies/ \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d chainId=43113 \
  -d name="Dynamic ERC20" \
  -d "strategy[sponsorSchema]=charge_custom_tokens" \
  -d "strategy[tokenContract]=con_..." \
  -d "strategy[tokenContractAmount]=1"

3. Fixed ERC20 Payment

Users pay a fixed amount of ERC20 tokens per transaction.

Dashboard

PolicyERC20Payment

API

curl https://api.openfort.io/v1/policies/ \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d chainId=80002 \
  -d name="Fixed ERC20" \
  -d "strategy[sponsorSchema]=fixed_rate" \
  -d "strategy[tokenContract]=con_..." \
  -d "strategy[tokenContractAmount]=10000"

Policy Rules

While strategies determine how gas fees are paid, rules define when and how your gas policy applies. Every policy needs at least one rule to function, and you can choose from three types:

Rule ModelDescription
contract_functionsSponsor interactions with smart contracts.
account_functionsSponsor interactions with the smart account.
limit_rulesLimit the amount of gas or number of transactions over an interval.

Contract functions

These rules let you specify which smart contract interactions your policy covers. You might want to sponsor all interactions with your game contracts but not with external marketplaces, for instance.

Wildcard policy

To create a policy rule, you need first to add a contract to Openfort:

Add a contract

API

Add a contract to Openfort to an API request:

curl https://api.openfort.io/v1/contracts \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d name="SimpleNFT" \
  -d address="0x416c...354D" \
  -d chainId="80002"
Dashboard

Add a new contract by clicking the Add contract button in the Asset contracts section, then enter:

  • The name of the contract (it can be any name you want; the name is only for identification purposes)
  • The network (chainId) where the smart contract is located.
  • The address of the contract.
  • The Application Binary Interface (ABI) of the contract (if not verified in the block explorer of that network).

DashboardAddContract

Once you've selected your contract, you can then choose what function you wish to enable sponsorship for. You can select All functions instead to allow sponsoring all functions in that specific contract.

Dashboard

policyRules

API

curl https://api.openfort.io/v1/policy_rules \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d type="contract_functions" \
  -d functionName="mint" \
  -d "contract=con_..."

Account functions

These rules cover account-related operations, such as transferring ownership of accounts, managing session keys, or deploying smart accounts. They're essential for maintaining smooth account management operations within your application.

Dashboard

Register Session key

API

curl https://api.openfort.io/v1/policy_rules \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d type="account_functions"

Limit rule

Limit rules help you control usage of your gas policy. You can set limits based on:

Rule TypeDescriptionExample Use Case
Gas per IntervalTotal gas limit in timeframe1000 WEI/minute
Gas per TransactionGas limit per transaction100 WEI/transaction
Count per IntervalTransaction count limit10 transactions/minute

Dashboard

Register Session key

API

curl https://api.openfort.io/v1/policy_rules \
  -H "Authorization: Bearer $YOUR_SECRET_KEY" \
  -d type="rate_limit" \
  -d functionName="gas_per_transaction" \
  -d gasLimit="1000000"