Skip to main content

zEVM contracts are fully EVM-compatible. This means you can deploy a basic solidity contract like this on ZetaChain.

pragma solidity 0.8.13;
contract HelloZeta {
function helloZeta() public pure returns (string memory) {
return "Hello Zeta";

However, what is special about zEVM contracts is that you can manage native assets on any connected chain through a simple interface.

A more complex example shows how one would build a cross-chain DEX based on UniswapV2 (don’t worry, this is simpler than it sounds!). Let’s dive into the code:

contract ZEVMSwapApp is zContract {
address public router02;
constructor(address router02_) {
router02 = router02_;

// Call this function to perform a cross-chain swap
function onCrossChainCall(address zrc20, uint256 amount, bytes calldata message) external override {
address targetZRC20;
address receipient;
uint256 minAmountOut;
(targetZRC20, receipient,minAmountOut) = abi.decode(message, (address,address,uint256));
address[] memory path;
path = new address[](2);
path[0] = zrc20;
path[1] = targetZRC20;
// Approve the usage of this token by router02
IZRC20(zrc20).approve(address(router02), amount);
// Swap for your target token
uint256[] memory amounts = IUniswapV2Router01(router02).swapExactTokensForTokens(amount, minAmountOut, path, address(this), block.timestamp);
// Withdraw amountto target recipient
IZRC20(targetZRC20).withdraw(abi.encodePacked(receipient), amounts[1]);

Note how simple this is: a cross-chain DEX pool in ~20 lines of code! All a user application needs to do is call onCrossChainCall, and the function can take any ZRC-20 token (Bitcoin, Ethereum, USDC, or any asset on any network) to swap for any other token. The withdraw call will output the target asset to a native address. This all happens in one step, as if you were operating on a single blockchain. The user just signs a transaction in their Metamask and performs a cross-chain swap. Once the transaction is complete, the output is known. The user does not need to wait on a message to be delivered to know what the result is.

With just a few additional lines of code, develoeprs can build on existing EVM-compatible protocols like Uniswap, Aave, Compound, Curve, etc. to create new omnichain DeFi products.