This guide will help you quickly integrate Permit3 into your application, enabling cross-chain token approvals and transfers with witness functionality.
Prerequisites
- An Ethereum development environment (Hardhat, Foundry, etc.)
- Basic understanding of EIP-712 signatures
- Familiarity with ERC20 tokens
- Access to the Permit3 contract address on your target chain(s)
Installation
Using npm
Using Foundry
Basic Integration
Initialize Permit3 Interface
User Setup
Users need to approve Permit3 to spend their tokens (once per token):
Creating and Signing Permits
Simple Token Transfer
The chainId in the domain object must ALWAYS be set to 1, regardless of which chain the permit is for.
This is because Permit3 uses a universal signature scheme where permits are signed once with chainId: 1
and can then be used across multiple chains.The actual chain where the permit will be executed is specified
separately in the permit data itself (e.g., in chainPermits.chainId), NOT in the EIP-712 domain.
Changing the domain chainId from 1 will cause signature verification to fail.
4. Executing Permits
Using Witness Functionality
Witness functionality allows you to include arbitrary data in your permits for enhanced verification.
1. Define Your Witness Data
2. Sign Witness Permit
3. Execute Witness Permit
Cross-Chain Operations
Permit3 supports cross-chain operations with a single signature.
1. Create Permits for Multiple Chains
2. Generate Merkle Tree
3. Sign and Execute on Each Chain
Common Operations
Setting an Allowance
Decreasing an Allowance
Locking an Account
Unlocking an Account
Best Practices
- Use Unique Salts: Generate cryptographically secure random values for salts
- Set Reasonable Deadlines: Keep signature validity periods as short as practical
- Validate Chain IDs: Always verify chain IDs match when processing cross-chain permits
- Handle Expiration: Check for expired signatures before attempting to process them
- Validate Witness Data: Verify witness data matches expected values before taking action
- Monitor Allowances: Track allowance changes to prevent unexpected behavior
- Test Thoroughly: Test all permit scenarios, including error cases
- Gas Optimization: Batch related operations when possible
Troubleshooting
Signature Verification Fails
- Ensure domain parameters (name, version, chainId, verifyingContract) are correct
- Verify the signer is the token owner
- Check salt hasn’t been used before
- Ensure deadline is in the future
- Verify chainId matches the current chain
Cross-Chain Issues
- Ensure hash chaining is correct (order matters)
- Verify each chain’s proof contains the correct hashes
- Check chainId matches for each chain
- Ensure the same salt and deadline are used across chains
Witness Verification Problems
- Verify witness type string is properly formatted (must end with ’)’)
- Ensure witness data matches expected values
- Check EIP-712 type definitions are consistent across frontend and contracts