Overview
Onchain Tokens enable you to maintain a blockchain-based ERC20 representation of any loyalty currency in Snag. When enabled, user point balances are automatically synchronized on-chain at configurable intervals, allowing your loyalty program to integrate seamlessly with smart contracts, DEXs, and other on-chain applications.Onchain tokens are perfect for projects that want to combine the flexibility of off-chain loyalty systems with the composability and transparency of blockchain technology.
How It Works
Snag’s onchain token system uses a hybrid approach that combines the best of both worlds:- Off-chain tracking: User balances are tracked in Snag’s high-performance database
- Periodic synchronization: Balance changes are batched and synced on-chain at regular intervals
- Efficient execution: Batch operations minimize gas costs and maximize throughput
Synchronization Process
1
Balance calculation
Snag calculates the delta (difference) between off-chain balances and on-chain balances for all users since the last sync.
2
Batch preparation
Users requiring mints or burns are grouped into optimized batches. If the dataset is too large for a single transaction, it’s automatically split into multiple batches.
3
On-chain execution
The relayer executes
batchMint
or batchBurn
transactions to update balances on-chain.4
Confirmation
Once confirmed on-chain, the sync is complete and balances are updated. The cycle repeats at your configured interval.
Setting a faster sync interval will result in more frequent on-chain updates but will also increase your overall gas costs proportionally.
Contract Requirements
Snag supports two options for onchain tokens:Option 1: Snag Hybrid ERC20 (Recommended)
TheSnagHybridERC20
contract is a fully-featured, upgradeable ERC20 token optimized for loyalty programs. It includes:
- Batch operations:
batchMint
andbatchBurn
for efficient multi-user updates - Permission system: Granular control over who can send/receive tokens
- Role-based access: Separate roles for balance updates, admin, and upgrades
- Upgradeable: UUPS proxy pattern for future enhancements
The contract source code is available in our GitHub repository. Snag will deploy and configure the contract for you from your relayer address.
Option 2: Custom Contract
If you prefer to use your own token contract, it must expose the following functions:When using a custom contract, ensure the batch functions include proper access control to prevent unauthorized minting or burning.
Permissions & Security
To enable Snag to update balances on your token contract, you must grant the appropriate permissions to your relayer’s EOA (Externally Owned Account).Granting Permissions
Your contract should implement role-based access control (such as OpenZeppelin’s AccessControl). You’ll need to grant your relayer address the role that permits minting and burning tokens. ForSnagHybridERC20
, this is the BALLANCE_UPDATER_ROLE
. For custom contracts, grant whichever role allows calling your batch mint and burn functions.
Relayers are standard EOAs (not contract wallets), making execution straightforward and fully compatible with your existing role system.
Key Management
Snag uses enterprise-grade security for private key management:- GCP Cloud KMS: All private keys are stored in Google Cloud’s Key Management Service
- Hardware Security Modules (HSM): Signing operations occur inside secure hardware enclaves
- No key exposure: Private keys never leave the cloud infrastructure
V2 Relayers Only
Onchain tokens are exclusively supported on V2 relayers, which provide enhanced security with GCP Cloud KMS integration and improved transaction management.V1 relayers (AWS-based) do not support onchain token synchronization. Please migrate to V2 relayers to use this feature.
Gas & Funding
Relayer Funding
You are responsible for keeping your relayer funded with native tokens (ETH, MATIC, etc.) to pay for gas fees.1
Copy relayer address
Navigate to your relayer in Snag Admin and copy the EOA address.
2
Send funds
Transfer native tokens from any wallet to the relayer address. Ensure you’re on the correct network.
3
Monitor balance
Regularly check your relayer balance to ensure uninterrupted operation.
Fee Structure
Snag takes zero fees per transaction. You only pay network gas fees to the blockchain.
Performance & Scalability
Snag’s infrastructure is built to handle high-volume operations, supporting hundreds of thousands of accounts per sync cycle. The main constraint is the blockchain itself—specifically, one transaction per EOA per block. Batching operations significantly improves both gas efficiency and throughput. Without batching, on-chain balances could never sync efficiently—each transaction would need to wait for the previous one to confirm.For extremely high-volume use cases, we’re developing a relayer pool system that distributes load across multiple EOAs using round-robin, effectively removing throughput limits.
Transaction Reliability
All transaction management—including nonce sequencing, gas estimation, and error handling—is handled automatically by the relayer service. If issues arise (such as insufficient funds or permission errors), you’ll be notified to take corrective action.Migration & Control
Taking Full Control
If you want to manage token minting yourself in the future:1
Deploy your own relayer
Set up your own signing infrastructure and relayer service.
2
Update permissions
Revoke the balance updater role from Snag’s relayer and grant it to your relayer.
3
Implement sync logic
You can continue using Snag Admin to trigger syncs, or build your own synchronization solution.
The contract is deployed from your relayer and all configuration is handled for you. If you prefer to deploy it yourself, contact our team for guidance.
Audits
- Smart contracts: Halborn is currently auditing our airdrop protocol;
SnagHybridERC20
audit is expected to follow - Infrastructure audit: Completed 4-week white box security audit by Anvil Secure’s lead security researcher
- Regular audits: Both smart contracts and application infrastructure undergo periodic security reviews
Frequently Asked Questions
What chains are supported?
What chains are supported?
Any EVM-compatible chain where you have a V2 relayer. Popular chains include Ethereum, Arbitrum, Polygon, Base, Optimism, and more. Solana support is coming soon (keys are managed in GCP but hardware signing is not yet available).
Can I use this with existing token contracts?
Can I use this with existing token contracts?
Yes! As long as your contract exposes
batchMint
and batchBurn
functions with proper access control, you can use it with Snag’s onchain token system. You can also deploy a proxy contract to add these functions to existing tokens.What happens if my relayer runs out of gas?
What happens if my relayer runs out of gas?
Transactions will fail to execute until you refund the relayer. Snag will alert you when balances are low.
How often should I sync balances?
How often should I sync balances?
This depends on your use case and budget. More frequent syncs provide near real-time updates but cost more in gas fees. Less frequent syncs (hourly or daily) are more cost-effective. You can adjust this anytime in Snag Admin.
What's the difference between V1 and V2 relayers?
What's the difference between V1 and V2 relayers?
V2 relayers use GCP Cloud KMS with hardware signing and support onchain token synchronization. V1 relayers use AWS KMS and do not support onchain tokens. All new projects should use V2 relayers.
Can I track transactions on a block explorer?
Can I track transactions on a block explorer?
Absolutely! All transactions are public on-chain. You can view them on explorers like Etherscan, Arbiscan, or Polygonscan by searching for your relayer’s address.
Is there support for EIP-7702 (delegation)?
Is there support for EIP-7702 (delegation)?
Our relayers support EIP-7702 but we haven’t integrated it for hybrid ERC20 yet, as this standard is still propagating and many partner blockchains don’t support it. We’re monitoring adoption and will integrate when appropriate.