Skip to main content

VIAMintBurnTokenMinimal

A cross-chain ERC20 token that burns on the source chain and mints on the destination. Total supply stays constant across all chains. This is the reference implementation from the VIA Labs contract suite.

Use when you control the token — you have mint/burn authority on every chain.

Building a route to Cardano?

Use VIAMintBurnTokenCardano instead. This contract encodes its message with abi.encode, and a Cardano client cannot decode that format.

For the full source code, see Contract Source. For the deployment walkthrough, see Burn & Mint Token.

Inherits: ERC20, ERC20Burnable, Ownable, ViaIntegrationV1


Constructor​

constructor(string memory name, string memory symbol, uint256 initialSupply)
ParameterTypeDescription
namestringToken name (e.g., "My Token")
symbolstringToken symbol (e.g., "MTK")
initialSupplyuint256Supply in whole tokens — multiplied by 10 ** decimals()

Deployer becomes both the ERC20 owner and the ViaIntegrationV1 projectOwner.


Functions​

mint​

function mint(address to, uint256 amount) external onlyOwner;

Mint tokens to any address. Restricted to owner.

bridge​

function bridge(
bytes32 tokenRecipient,
uint64 destChainId,
uint256 amount
) external payable returns (uint256 txId);

Burn tokens from msg.sender on this chain and send a message to mint on the destination.

ParameterTypeDescription
tokenRecipientbytes32Recipient address on destination chain (left-padded). Use _addressToBytes32().
destChainIduint64Destination chain ID
amountuint256Amount to bridge (in wei)

Include msg.value for destination gas. Returns a txId for tracking.

messageProcess​

function messageProcess(
uint256 txId, uint64 sourceChainId, bytes32 sender, bytes32 recipient,
bytes memory onChainData, bytes memory offChainData, uint256 gasRefundAmount
) internal override;

Called automatically by the gateway. Decodes (bytes32 tokenRecipient, uint256 amount) from onChainData and mints to the recipient.


Message Encoding​

// bridge() encodes:
abi.encode(bytes32 tokenRecipient, uint256 amount)

// messageProcess() decodes:
(bytes32 tokenRecipient, uint256 amount) = abi.decode(onChainData, (bytes32, uint256));

Errors​

ErrorWhen
ZeroAmountbridge() called with amount == 0
InvalidMessageDecoded amount < 1 or recipient is zero address

Burns are irreversible. If messageProcess() fails on the destination, tokens are already burned on the source. Recovery requires the owner to manually mint() replacements.