ERC20WrappedxWithAuthorize
Kit The ERC20WrappedxWithAuthorize contract lets you upgrade your existing ERC20 token to support gasless, authorized transfers and burns using EIP-712 signatures. Instantly add meta-transaction and relayer support to your token, enabling flexible, secure, and advanced transfer flows.
Import
import "isol/contracts/kit/ERC20WrappedxWithAuthorize.sol";Usage
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import "isol/contracts/kit/ERC20WrappedxWithAuthorize.sol";
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address,
"WERC20xAuth Token",
"WAUTH",
"WERC20xAuth Token",
"1"
)
{}
}Arguments
| Parameter | Type | Description |
|---|---|---|
underlyingToken | address | The address of the underlying ERC20 token |
name | string | The name of your token |
symbol | string | The symbol (ticker) of your token |
domainName | string | EIP-712 domain name for signature verification |
domainVersion | string | EIP-712 domain version for signature verification |
underlyingToken
- Type:
address
The address of the underlying ERC20 token, e.g., 0x..1234.
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string)
)
{}
}name
- Type:
string
The name of your ERC20 token, e.g., "MyToken".
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string)
)
{}
}symbol
- Type:
string
The symbol (ticker) of your ERC20 token, e.g., "MTK".
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string)
)
{}
}domainName
- Type:
string
The EIP-712 domain name used for signature verification, e.g., "MyToken".
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string)
)
{}
}domainVersion
- Type:
string
The EIP-712 domain version used for signature verification, e.g., "1".
contract WrapERC20xAuth is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string)
)
{}
}Functions
Read
| Function | Arguments | Description |
|---|---|---|
BURN_TYPEHASH | - | Check the typehash used for burn authorization |
TRANSFER_TYPEHASH | - | Check the typehash used for transfer authorization |
allowance | owner (address), spender (address) | Check approved amount for spender |
authorizeState | authorizer (address), nonce (bytes32) | Check authorization state |
balanceOf | account (address) | Get token balance of an address |
decimals | - | Get number of decimals used by the token |
eip712Domain | - | Check the EIP-712 domain used for signature verification |
name | - | Get the name of the token |
owner | - | Get the owner of the token |
symbol | - | Get the symbol of the token |
totalSupply | - | Get the total supply of the token |
underlying | - | Get the underlying token address |
Write
| Function | Interact | Arguments | Description |
|---|---|---|---|
approve | user | spender (address), value (uint256) | Allow spender to use your tokens |
burn | user | value (uint256) | Burn a specific amount of your tokens |
burnFrom | user | account (address), value (uint256) | Burn a specific amount of your tokens from an account |
burnWithAuthorize | user | from (address), value (uint256), createTime (uint256), expireTime (uint256), nonce (bytes32), auth (bytes) | Burn tokens with authorization |
depositFor | user | account (address), value (uint256) | Deposit tokens for an account |
renounceOwnership | owner | - | Renounce ownership of the token |
transfer | user | to (address), value (uint256) | Send tokens to another address |
transferFrom | user | from (address), to (address), value (uint256) | Move tokens using allowance |
transferOwnership | owner | newOwner (address) | Transfer ownership of the token |
transferWithAuthorize | user | from (address), to (address), value (uint256), createTime (uint256), expireTime (uint256), nonce (bytes32), auth (bytes) | Transfer tokens with authorization |
withdrawTo | user | account (address), value (uint256) | Withdraw tokens to an account |
Events
| Logs |
|---|
Transfer(address indexed from, address indexed to, uint256 value) |
Approval(address indexed owner, address indexed spender, uint256 value) |
OwnershipTransferred(address indexed previousOwner, address indexed newOwner) |
BurnWithAuthorize(address sender, address from, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth) |
TransferWithAuthorize(address sender, address from, address to, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth) |
Features
Functions are inherited from ERC20xTransferWithAuthorize, with additional new features below.
| Function | Type | Interact | Arguments | Description |
|---|---|---|---|---|
underlying | read | - | - | Check authorization state. |
depositFor | write | user | account (address), value (uint256) | Deposit tokens for an account |
withdrawTo | write | user | account (address), value (uint256) | Withdraw tokens to an account |
References
Source code: ERC20WrappedxWithAuthorize
OpenZeppelin: ERC20, ERC20Burnable, ERC20Wrapper, ReentrancyGuard, Ownable
Examples
Deploy
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import "isol/contracts/kit/ERC20WrappedxWithAuthorize.sol";
contract MyToken is ERC20WrappedxWithAuthorize {
constructor()
ERC20WrappedxWithAuthorize(
0x...YouERC20Address, // Underlying Token (address)
"WERC20xAuth Token", // Name (string)
"WAUTH", // Symbol (string)
"WERC20xAuth Token", // Domain Name (string)
"1" // Domain Version (string
)
{}
}Interact
import { daccSignTypedData } from "dacc-js";
import { createWalletClient, http } from 'viem';
import { parseAbi, toHex } from "viem";
import { privateKeyToAccount } from 'viem/accounts';
import { optimismSepolia } from "viem/chains";
// ==========================================
// CONFIG FOR SIGNING
// ==========================================
const domainName = "WERC20_X_AUTH";
const domainVersion = "VERSION";
const chainId = 11155420; // number
const contract = "WERC20_X_AUTH...CONTRACT_ADDRESS";
const walletAddress = "FROM...WALLET_ADDRESS";
const toAddress = "TO...WALLET_ADDRESS";
const amount = 1000000000000000000n; // decimal
const nonce = crypto.getRandomValues(new Uint8Array(32)); // bytes32
const now = Math.floor(Date.now() / 1000);
const createTime = now - 60;
const expireTime = now + 3600;
const daccID = "DACC_PUBLIC_KEY";
const daccPassword = "DACC_PASSWORD_SECRETKEY";
const sponsorPrivateKey = "0X...PRIVEATE_KEY";
// ==========================================
// SIGNING WITH DACC-JS
// ==========================================
const signed = await daccSignTypedData({
daccPublickey: daccID,
passwordSecretkey: daccPassword,
network: optimismSepolia,
domain: {
name: domainName,
version: domainVersion,
chainId: chainId,
verifyingContract: contract
},
types: {
TransferWithAuthorize: [
{ name: "from", type: "address" },
{ name: "to", type: "address" },
{ name: "value", type: "uint256" },
{ name: "createTime", type: "uint256" },
{ name: "expireTime", type: "uint256" },
{ name: "nonce", type: "bytes32" }
]
},
primaryType: "TransferWithAuthorize",
message: {
from: walletAddress,
to: toAddress,
value: amount,
createTime,
expireTime,
nonce: toHex(nonce)
}
});
// console.log('Signed Data:', signed);
// ==========================================
// SEND TRANSACTION WITH VIEM
// ==========================================
const walletClient = createWalletClient({
account: privateKeyToAccount(sponsorPrivateKey as `0x${string}`),
chain: optimismSepolia,
transport: http(),
});
const abiContract = parseAbi([
'function transferWithAuthorize(address from, address to, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes calldata auth)',
]);
const tx = await walletClient.writeContract({
address: contract as `0x${string}`,
abi: abiContract,
functionName: "transferWithAuthorize",
args: [
walletAddress as `0x${string}`,
toAddress as `0x${string}`,
BigInt(amount),
BigInt(createTime),
BigInt(expireTime),
toHex(nonce),
signed.signature
],
});
console.log('Transaction Hash:', tx);