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
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
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
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 Model | Description |
---|---|
contract_functions | Sponsor interactions with smart contracts. |
account_functions | Sponsor interactions with the smart account. |
limit_rules | Limit 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.
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).
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
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
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 Type | Description | Example Use Case |
---|---|---|
Gas per Interval | Total gas limit in timeframe | 1000 WEI/minute |
Gas per Transaction | Gas limit per transaction | 100 WEI/transaction |
Count per Interval | Transaction count limit | 10 transactions/minute |
Dashboard
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"