N3 to EVM
Overview
Complete Flow Steps
Step 1: Prepare the EVM Call Structure
const { ethers } = require('ethers');
// Define the Neo token contract address on EVM and target address
const neoTokenContractAddress = "0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f"; // Neo token address on Neo X Testnet
const targetAddress = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"; // Address to check the balance for
// Create the interface for ERC20 balanceOf function
const erc20Interface = new ethers.Interface([
"function balanceOf(address account) view returns (uint256)"
]);
// Encode the balanceOf function call
const callData = erc20Interface.encodeFunctionData("balanceOf", [targetAddress]);
console.log("Encoded balanceOf callData:", callData);
// Output: 0x70a08231000000000000000000000000abcdefabcdefabcdefabcdefabcdefabcdefabcd
// Create the EVM Call structure (equivalent to AMBTypes.Call)
const evmCall = {
target: neoTokenContractAddress, // Target EVM Neo token contract
allowFailure: false, // Don't allow failure
value: 0, // No gas value needed for the call
callData: callData // Encoded balanceOf(address) call data
};
// Serialize the entire Call structure using ethers ABI encoder
const callStructAbi = [
"tuple(address target, bool allowFailure, uint256 value, bytes callData)"
];
const abiCoder = new ethers.AbiCoder();
const serializedMessage = abiCoder.encode(callStructAbi, [evmCall]);
console.log("Serialized Call message:", serializedMessage);Step 2: Send Executable Message from N3
Step 3: Message Relay to the EVM Chain
Step 4: Message Execution on EVM
Step 5: Verify Execution Results
Step 6: Return Result back to N3
Step 7: Message Relay back to N3
Example Implementation (JavaScript)
Visualization
Last updated