Skip to main content

NAC Usage: EVM to Michelson

Cross-interface calls go through the gateway contract of the caller's interface. This page describes how to initiate a cross-interface call from the EVM interface. For the opposite way, see Michelson to EVM.

The EVM-to-Michelson gateway is a precompile deployed at:

0xff00000000000000000000000000000000000007

callMichelson​

Call a Michelson contract by providing:

ParameterTypeDescription
destinationstringThe Michelson contract address (KT1… base58check)
entrypointstringThe target entrypoint name
databytesMichelson-encoded parameters

A Michelson KT1… address is 22 bytes in base58check form and does not fit into a 20-byte EVM address type. The gateway therefore takes the destination as a string and parses it on the Michelson side.

interface INativeAtomicGateway {
function callMichelson(
string calldata destination,
string calldata entrypoint,
bytes calldata data
) external payable;
}

INativeAtomicGateway gateway = INativeAtomicGateway(
0xff00000000000000000000000000000000000007
);
gateway.callMichelson("KT1…", "default", michelsonParams);

The data parameter must be encoded in Michelson binary format. For simple types you can construct the payload inline: for example, passing a nat with value 42 encodes as hex"002a" (tag 0x00 = integer, value 0x2a = 42). Worked Solidity examples using this pattern are available in the solidity_examples/ directory of the Etherlink sources. For complex types, off-line tools such as the packData function in octez.js (or in Taquito) can compute the encoding.

A Michelson call (via callMichelson) has no return value.

callMichelsonView​

To call a read-only Michelson view and receive the result, use callMichelsonView:

ParameterTypeDescription
destinationstringThe Michelson contract address (KT1… base58check)
viewNamestringThe name of the on-chain view
inputbytesMicheline-encoded input to the view

This entry point performs a read-only crossing (no value transfer, no state mutation) and must be invoked via staticcall. The gateway returns the view's Micheline response ABI-encoded as bytes.

interface INativeAtomicGateway {
function callMichelsonView(
string calldata destination,
string calldata viewName,
bytes calldata input
) external view returns (bytes memory);
}

INativeAtomicGateway gateway = INativeAtomicGateway(
0xff00000000000000000000000000000000000007
);
bytes memory michelineResult = gateway.callMichelsonView(
"KT1…", // destination
"myView", // view name
hex"030b" // Micheline Unit — adjust to match the view's input type
);

A complete worked example (using the low-level staticcall pattern) is available in crac_michelson_view_staticcall.sol.

Address translation​

Cross-interface calls run under the caller's alias (see Accounts and Aliases). The gateway exposes two view functions to translate between native addresses and aliases. Both take the address as a string in its printable form (0x… hex for the EVM interface, base58check for the Michelson interface) rather than as a Solidity address, and identify interfaces by a runtime id: 0 for the Michelson interface, 1 for the EVM interface.

interface INativeAtomicGateway {
function originOf(
string calldata addr,
uint8 sourceRuntime
) external view returns (uint8 kind, uint8 homeRuntime, string memory nativeAddress);

function resolveAddress(
string calldata addr,
uint8 sourceRuntime,
uint8 targetRuntime
) external view returns (bool classified, uint8 res, string memory translated);

error InvalidRuntimeId(uint8 received);
}

originOf​

originOf(addr, sourceRuntime) returns how the address addr of the interface sourceRuntime is classified:

kindMeaninghomeRuntimenativeAddress
0 (Unknown)The address is malformed or has not been seen by the kernel yet0""
1 (Native)An account native to sourceRuntimesourceRuntimeaddr
2 (Alias)The alias of an account native to the other interfaceThe interface the account is native toThe native address of that account

The kernel records the origin of an account when it is first used: Michelson user accounts (tz1…, tz2…, tz3…) are always Native, Michelson smart contracts are recorded at origination, EVM accounts when they first sign a transaction or when they have code, and aliases when a cross-interface call creates them or when they are materialized on demand. In particular, an EVM address that has only received funds is Unknown.

For example, to check whether the caller is a Michelson account:

(uint8 kind, , string memory native) = gateway.originOf(
Strings.toHexString(msg.sender), // OpenZeppelin helper: lowercase "0x…" string
1
);
if (kind == 2) {
// msg.sender is the alias of the Michelson account `native` (tz1… or KT1…)
}

resolveAddress​

resolveAddress(addr, sourceRuntime, targetRuntime) translates the address addr of the interface sourceRuntime into the corresponding address of the interface targetRuntime:

  • If addr is malformed or Unknown, classified is false and the other values are zero.
  • If addr is Native, translated is its alias in targetRuntime.
  • If addr is an Alias, translated is the native address it stands for, rather than an alias of the alias.

res is 0 (Recorded) when the returned address already exists on chain and 1 (Derived) when it was computed with the derivation formula but no cross-interface call has created the alias yet. When sourceRuntime and targetRuntime are equal, a well-formed address is returned unchanged with res == 0.

(bool classified, uint8 res, string memory evmAlias) = gateway.resolveAddress(
"tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb", 0, 1
);
// classified == true; evmAlias is the "0x…" EVM alias of the Tezos account;
// res == 1 until a cross-interface call or materializeAlias creates the alias

Materializing aliases​

An alias is normally created the first time its native account makes a cross-interface call. Starting with Etherlink 8.0, anyone can also create (materialize) the EVM alias of a Michelson account on demand with the materializeAlias function of the gateway. This is useful, for example, when a dApp needs the alias to exist on chain before the Michelson account makes its first cross-interface call, so that originOf recognizes it as an alias, or so that it can verify the account's signatures through EIP-1271.

interface INativeAtomicGateway {
function materializeAlias(
string calldata nativeRuntime,
string calldata nativeAddress,
string calldata nativePublicKey
) external returns (address aliasAddress);

event AliasMaterialized(
string nativeRuntime,
string nativeAddress,
address aliasAddress
);
}
ParameterTypeDescription
nativeRuntimestringThe name of the runtime that the account is native to; currently, it must be "tezos"
nativeAddressstringThe native address of the account, in base58check form (tz… or KT1…)
nativePublicKeystringFor a user account, its public key in base58check form (for example, edpk…); for a smart contract, the empty string

The function returns the address of the EVM alias.

The kernel materializes only the alias of an account that it can prove to be native to the Michelson interface, so the alias of an alias can never be created:

  • For a user account, the public key is mandatory and must match the address. It is stored in the alias, which uses it to verify the account's signatures through EIP-1271.
  • For a smart contract, the public key must be empty, and the contract must have been originated. Enshrined contracts such as the gateway are refused, as are the Michelson aliases of EVM accounts.

The call is idempotent: if the alias already exists, it is left untouched and its address is returned. When the call creates the alias, the gateway emits an AliasMaterialized event, and the caller pays for the storage of the new alias as additional gas, on top of the base cost of the call. Afterwards, originOf classifies the address as an Alias and resolveAddress returns it as Recorded (res == 0).

address alias = gateway.materializeAlias(
"tezos",
"tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
"edpk…" // the public key of tz1VSUr8…
);

Materializing an alias does not move any funds. If tez were sent to the alias address before it was materialized, they stay there until the alias next receives a call or a transfer, at which point the alias forwards its whole balance to the native account. A call to the alias with zero value is enough to trigger this forwarding.

Failure behavior​

callMichelson​

If the Michelson callee fails for any reason — FAILWITH, type mismatch, non-existent contract, or forwarded gas exhaustion — the gateway precompile reverts the calling EVM transaction. All of them surface as an EVM revert with an error string containing a status code; the status code distinguishes a Michelson failure (400) from forwarded-gas exhaustion (429), so a contract that wants to react differently has to parse the string.

Because callMichelson is declared external payable (no return value), the revert propagates unconditionally to the EVM caller. To catch it without reverting your own transaction, call the precompile via a low-level call:

(bool success, ) = address(gateway).call{value: ...}(
abi.encodeWithSelector(
INativeAtomicGateway.callMichelson.selector,
destination, entrypoint, data
)
);
// success == false if Michelson reverted

Note that for the specific case when the Michelson callee fails by going out of gas (OOG), it is wise to reserve some gas to handle the failure, otherwise you would OOG yourself and everything would revert. See an examples of limiting the gas for the call in the NAC walkthrough.

callMichelsonView​

callMichelsonView follows the same failure model. Any of the following causes a revert that propagates to the EVM caller:

CauseEVM outcome
Michelson view fails (FAILWITH, etc.)Revert
View name does not exist on the contractRevert
Type mismatch on inputRevert
Forwarded gas exhausted in the Michelson viewRevert (not out-of-gas — catchable)

Because callMichelsonView must be invoked via staticcall, catch failures with low-level staticcall:

(bool success, bytes memory result) = address(gateway).staticcall(
abi.encodeWithSelector(
INativeAtomicGateway.callMichelsonView.selector,
destination, viewName, input
)
);
// success == false if the Michelson view reverted or was not found

originOf and resolveAddress​

Malformed addresses never revert: they are reported as Unknown (kind == 0) or unclassified (classified == false). Both functions revert with the custom error InvalidRuntimeId(uint8) when a runtime id is neither 0 nor 1.

materializeAlias​

materializeAlias reverts, with an error string starting with materializeAlias:, in the following cases:

  • It is invoked via staticcall or with a non-zero value.
  • nativeRuntime is not "tezos".
  • nativeAddress is malformed, or is not provably native, as described in Materializing aliases.
  • The public key is missing for a user account, given for a smart contract, malformed, or does not match the address.

The gas consumed by the checks is charged even when the call reverts.

Infrastructure failures​

A 5xx response from the Michelson runtime indicates a kernel-internal error (storage I/O failure, host fault). This is treated as a block-level abort rather than a catchable revert, meaning the entire block is rolled back. These failures are not caused by contract logic and are not catchable by EVM code.

Observability​

The EVM gateway precompile emits two events for cross-runtime calls involving the EVM interface. Both are emitted at the gateway precompile address and carry a crossRuntimeCallId field that correlates with the Michelson-side markers described in the Michelson nac-usage page.

CrossRuntimeCallSent​

Emitted on every outgoing call (EVM → other runtime), before execution:

FieldTypeDescription
crossRuntimeCallIdstringUnique identifier for this call
targetRuntimestringName of the target runtime (e.g. "tezos")
targetAddressstringAddress of the target contract
amountuint256Amount of tez forwarded with the call

CrossRuntimeCallReceived​

Emitted on every incoming call (other runtime → EVM), before execution:

FieldTypeDescription
crossRuntimeCallIdstringUnique identifier for this call
sourceRuntimestringNative runtime of the originating address (follows the transitive origin on nested calls, e.g. "ethereum" for an EVM → Michelson → EVM chain)
senderAddressstringImmediate caller — the EVM alias of the Michelson sender
sourceAddressstringTransitive origin — the original address at the start of the cross-runtime chain
targetAddressstringAddress of the called EVM contract
amountuint256Amount of tez forwarded with the call

AliasMaterialized​

Emitted at the gateway precompile address when materializeAlias creates a new alias (not when the alias already exists):

FieldTypeDescription
nativeRuntimestringName of the runtime the account is native to ("tezos")
nativeAddressstringNative address of the account
aliasAddressaddressAddress of the new EVM alias
arrow icon

Prev

Sending transactions

Next

arrow icon
Bridging tokens