Skip to main content

ViaIntegrationV1

The abstract base contract your project inherits from. It connects to the VIA Gateway, manages endpoint configuration, and routes cross-chain messages.

For the full source code, see Contract Source.


Messaging

These are the two functions you use in your contract.

messageSend

Send a cross-chain message. Call this from your contract's public functions.

function messageSend(
uint64 destChainId,
bytes memory chainData,
uint16 confirmations
) internal returns (uint256 txId);
ParameterTypeDescription
destChainIduint64Chain ID of the destination network
chainDatabytesABI-encoded payload
confirmationsuint16Block confirmations before processing. 0 = fastest, higher = safer.

Returns uint256 txId — unique identifier for tracking the message.

The caller must include msg.value to cover destination chain gas. Reverts with AddressZero if the gateway isn't set, or DestinationChainNotSet if the destination chain has no endpoint.

messageProcess

Override this to handle incoming messages. Called automatically by the gateway after validation.

function messageProcess(
uint256 txId,
uint64 sourceChainId,
bytes32 sender,
bytes32 recipient,
bytes memory onChainData,
bytes memory offChainData,
uint256 gasRefundAmount
) internal virtual;
ParameterTypeDescription
txIduint256Transaction ID from the source chain
sourceChainIduint64Chain ID where the message originated
senderbytes32Source contract address (left-padded)
recipientbytes32This contract's address (left-padded)
onChainDatabytesThe payload from messageSend()
offChainDatabytesAdditional relayer-provided data
gasRefundAmountuint256Gas refunded to the relayer

Configuration

All configuration functions are restricted to onlyProjectOwner.

setMessageGateway

function setMessageGateway(address gateway_) external onlyProjectOwner;

Connect to the VIA Gateway on this chain. Must be called before sending or receiving. Automatically queries the gateway for fee/gas collector addresses and approves their tokens.

setMessageEndpoints

function setMessageEndpoints(
uint64[] calldata chains,
bytes32[] calldata endpoints
) external onlyProjectOwner;

Map remote chain IDs to your contract addresses on those chains. Messages from unmapped chains are rejected.

ParameterTypeDescription
chainsuint64[]Remote chain IDs (e.g., [1, 137, 42161])
endpointsbytes32[]Your contract addresses on those chains (left-padded)

setMaxFee

function setMaxFee(uint256 amount) external onlyProjectOwner;

Cap the ERC-20 protocol fee per message. 0 = no cap. Currently fees are zero on all chains.

setMaxGas

function setMaxGas(uint256 amount) external onlyProjectOwner;

Cap the gas refund a relayer can claim per message. 0 = no cap. Only relevant for Ethereum mainnet destinations — see Fees & Gas.

transferProjectOwnership

function transferProjectOwnership(address newOwner) external onlyProjectOwner;

Single-step, immediate transfer. The new owner gets all onlyProjectOwner permissions. Cannot be set to zero address.


Advanced

Optional functions for enterprise projects that want additional control over security and relay infrastructure.

setSignerWhitelist

function setSignerWhitelist(address addr, bool enabled) external onlyProjectOwner;

Add/remove addresses from the project signer whitelist. Whitelisted addresses can register as Project-layer signers.

setRequiredProjectSignerCounts

function setRequiredProjectSignerCounts(uint256 amount) external onlyProjectOwner;

Set required project-layer signatures. 0 = disabled (rely on VIA and Chain layers only).

setRelayerWhitelist

function setRelayerWhitelist(address addr, bool enabled) external onlyProjectOwner;

Add/remove project-specific relayers.

setIsProjectRelayerRestricted

function setIsProjectRelayerRestricted(bool restricted) external onlyProjectOwner;

When true, only project-whitelisted relayers can deliver messages for your project.


Helpers

FunctionParametersReturnsDescription
_addressToBytes32address addrbytes32Convert address to bytes32 (left-padded)
_bytes32ToAddressbytes32 addraddressConvert bytes32 back to address

Errors

ErrorWhen
AddressZeroGateway not set, or transferProjectOwnership to zero address
DestinationChainNotSetNo endpoint configured for the destination chain
InvalidLengthchains and endpoints arrays have different lengths
NotOwnerCaller is not projectOwner
NotGatewayIncoming message not from the configured gateway
InvalidSenderIncoming message from an unrecognized source endpoint
NotAuthorizedCaller not in relayer/signer whitelist