diff --git a/src/pages/developers/chains/_meta.json b/src/pages/developers/chains/_meta.json index ae84787d0..4053ce526 100644 --- a/src/pages/developers/chains/_meta.json +++ b/src/pages/developers/chains/_meta.json @@ -17,7 +17,11 @@ }, "solana": { "title": "Solana", - "description": "Make calls to universal apps and deposit tokens from Solana" + "description": "Make calls to universal apps and deposit from Solana" + }, + "ton": { + "title": "Ton", + "description": "Make calls to universal apps and deposit from TON" }, "sui": { "title": "Sui", diff --git a/src/pages/developers/chains/evm.mdx b/src/pages/developers/chains/evm.mdx index b2d91fff7..fe1f40d0b 100644 --- a/src/pages/developers/chains/evm.mdx +++ b/src/pages/developers/chains/evm.mdx @@ -121,10 +121,10 @@ universal contract and passes the `payload` as the `message` parameter. The `call` function doesn't support revert handling. If `revertOptions.callOnRevert` is set to `true`, the transaction will fail. This -is because executing a contract call on revert requires tokens to cover gas -fees on ZetaChain, and the `call` function doesn't transfer any assets. If you -need to handle reverts, use `depositAndCall` instead and ensure sufficient -tokens are deposited to cover potential gas fees. +is because executing a contract call on revert requires tokens to cover gas fees +on ZetaChain, and the `call` function doesn't transfer any assets. If you need +to handle reverts, use `depositAndCall` instead and ensure sufficient tokens are +deposited to cover potential gas fees. ## Revert Transactions diff --git a/src/pages/developers/chains/ton.mdx b/src/pages/developers/chains/ton.mdx new file mode 100644 index 000000000..f6fa4c0d1 --- /dev/null +++ b/src/pages/developers/chains/ton.mdx @@ -0,0 +1,68 @@ +To interact with universal applications from TON, use the TON gateway. + +TON gateway supports: + +- Depositing TON to a universal app or an account on ZetaChain +- Depositing TON and calling a universal app +- Withdrawing TON from ZetaChain + +## Deposit TON + +To deposit TON to an EOA or a universal contract, send an internal message to +the Gateway contract with the following structure: + +```func +op_code:uint32 query_id:uint64 evm_recipient:slice (160 bits) +``` + +The deposit `op_code` is `101`. `query_id` is reserved for future use, leave it +to `0`. + +The `evm_recipient` specifies the address on ZetaChain that will receive the +deposited TON. This can be either an externally-owned account (EOA) or a +universal app address. + +Here's an example of how to construct the deposit message in TypeScript: + +```typescript +const opDeposit = 101; +const body = beginCell().storeUint(opDeposit, 32).storeUint(0, 64).storeUint(zevmRecipient, 160).endCell(); +``` + +After the deposit is processed, the receiver receives the [ZRC-20 +version](/developers/tokens/zrc20) of the deposited TON. + +## Deposit TON and Call a Universal App + +To deposit TON and call a universal app contract, send an internal message to +the Gateway contract with the following structure: + +```func +op_code:uint32 query_id:uint64 evm_recipient:slice (160 bits) call_data:cell +``` + +The depositAndCall `op_code` is `102`. `query_id` is reserved for future use, +leave it to `0`. Also note that call_data should be a cell encoded in ["snake +data"](https://docs.ton.org/v3/guidelines/dapps/asset-processing/nft-processing/metadata-parsing#snake-data-encoding) +format (supported by most TON libraries) + +The `evm_recipient` must be the address of a universal app contract. + +The `call_data` cell contains the payload that will be passed to the `onCall` +function of the universal app contract. + +Here's an example of how to construct the deposit-and-call message in +TypeScript: + +```typescript +const opDepositAndCall = 102; +const body = beginCell() + .storeUint(opDepositAndCall, 32) + .storeUint(0, 64) + .storeUint(zevmRecipient, 160) + .storeRef(callDataCell) // callDataCell should be a cell containing the payload + .endCell(); +``` + +After the cross-chain transaction is processed, the `onCall` function of the +universal app contract is executed.