Gas Policies
Gas payments on Openfort are managed by policies. They enable you to define the contracts and/or functions that your users can interact with without incurring gas costs in native tokens. By specifying these policies, you can control the way your players interact with the in-game items and currencies.
Overview
By default, web3 users are responsible for paying their own gas fees. However, with gas policies you can choose to sponsor transactions's gas fees or to let your users pay such fees in other tokens. This document will guide you through the process of setting up gas policies to ensure a secure and controlled approach.
This opens up a world of possibilities, including:
- New users can perform on-chain actions without having to acquire the native network token first.
- Games can cover gas fees for their users to encourage adoption.
- Policies can allow users to pay for gas using a stablecoin like USDC or any other ERC20 token (ie. in-game token).
- You could sponsor actions that help your game adoption, but keep the payment of gas fees for actions required for leaving your gaming ecosystem.
How Gas Policies Work
You can use gas policies to specify the contracts and functions that you want your users to interact with without paying gas fees in native tokens. Read more in our article about Gas Sponsorship in Openfort.
Add an Asset Contract
To use contract policies, you first need to add your asset contract.
To set up your first gas policy navigate first to the Gas Policies tab.
Then click on the top right button Add Policy
to start filling the Policy Information.
Sponsorship strategies
There are two types of gas policies that you can implement:
- Pay gas for user: pay gas fees on behalf of your users using the native token (ie. ETH, MUMBAI, AVAC, etc.).
- Charge gas in custom tokens: the players can pay gas fees with any ERC20 token (ie. USDC, in-game token, etc.)

Policy Rules
Policy rules are the conditions that you can set to apply the gas policy.
-
When selecting
contract_functions
as the policy rule, you can decide what asset contract and functions are allowed to be called by your users.Then, you can select either
All functions
or some specific functions to further restrict the policy. -
When selecting
account_functions
as the policy rule, the affected policy will be applied for the registration of new session keys.
Rate Limits (coming soon)
There will be four types of rate limits:
- Amount: limit by the amount of gas
- Request: limit by the number of requests
- Gas Price: limit by the current gas price
- Amount per tx: limit by the amount of gas per transaction
Quickstart
1. (API) Create a new policy
Here is an example to create a new policy to charge gas fees in custom tokens:
Create a policy for charging in custom tokens
curl https://api.openfort.xyz/v1/policies/ \ -H "Authorization: Bearer $YOUR_SECRET_KEY"
\ -d chain_id=5 \ -d name="TEST" \ -d "strategy[sponsor_schema]=charge_custom_tokens"
\ -d "strategy[token_contract]=con_..." \ -d "strategy[token_contract_amount]=10000"
Where the contract con_
is the asset contract of the ERC20 token that you want to use to charge the gas fees.
In this guide, we'll use a simple ERC20 contract on the Mumbai network deployed at 0x7ef8059db4d9696b261714989f05bf68173de1f0.
The endpoint below can be used to list the policy rules related to a policy:
Create a policy rules for the policy
curl https://api.openfort.xyz/v1/policy_rules \ -H "Authorization: Bearer $YOUR_SECRET_KEY"
\ -d type="Allowed functions" \ -d function_name="mint" \ -d "contract=con_..."
For more details, you can visit the Policies documentation in the API reference.
1. (Dashboard) Create a new policy
-
Sponsor minting an in-game asset
To let players mint new shields on a given web3 game for free, one could set the next gas policy up. This way, the gas fees (in MATIC) incurred from players minting new shields would be sponsored by the game. With this gas policy, players would still need to pay fees for other actions like transfering those shields.
-
Let players register session keys in custom token
The following example policy would allow users to register new session keys paying the related costs in a custom token.
2. (Dashboard) View & control gas spending
Each transaction intent will appear in the profile of the policy that was used to sponsor it as well as the amount of gas spent.
