|
| 1 | +To interact with universal applications from TON, use the TON gateway. |
| 2 | + |
| 3 | +TON gateway supports: |
| 4 | + |
| 5 | +- Depositing TON to a universal app or an account on ZetaChain |
| 6 | +- Depositing TON and calling a universal app |
| 7 | +- Withdrawing TON from ZetaChain |
| 8 | + |
| 9 | +## Deposit TON |
| 10 | + |
| 11 | +To deposit TON to an EOA or a universal contract, send an internal message to |
| 12 | +the Gateway contract with the following structure: |
| 13 | + |
| 14 | +```func |
| 15 | +op_code:uint32 query_id:uint64 evm_recipient:slice (160 bits) |
| 16 | +``` |
| 17 | + |
| 18 | +The deposit `op_code` is `101`. `query_id` is reserved for future use, leave it |
| 19 | +to `0`. |
| 20 | + |
| 21 | +The `evm_recipient` specifies the address on ZetaChain that will receive the |
| 22 | +deposited TON. This can be either an externally-owned account (EOA) or a |
| 23 | +universal app address. |
| 24 | + |
| 25 | +Here's an example of how to construct the deposit message in TypeScript: |
| 26 | + |
| 27 | +```typescript |
| 28 | +const opDeposit = 101; |
| 29 | +const body = beginCell().storeUint(opDeposit, 32).storeUint(0, 64).storeUint(zevmRecipient, 160).endCell(); |
| 30 | +``` |
| 31 | + |
| 32 | +After the deposit is processed, the receiver receives the [ZRC-20 |
| 33 | +version](/developers/tokens/zrc20) of the deposited TON. |
| 34 | + |
| 35 | +## Deposit TON and Call a Universal App |
| 36 | + |
| 37 | +To deposit TON and call a universal app contract, send an internal message to |
| 38 | +the Gateway contract with the following structure: |
| 39 | + |
| 40 | +```func |
| 41 | +op_code:uint32 query_id:uint64 evm_recipient:slice (160 bits) call_data:cell |
| 42 | +``` |
| 43 | + |
| 44 | +The depositAndCall `op_code` is `102`. `query_id` is reserved for future use, |
| 45 | +leave it to `0`. Also note that call_data should be a cell encoded in ["snake |
| 46 | +data"](https://docs.ton.org/v3/guidelines/dapps/asset-processing/nft-processing/metadata-parsing#snake-data-encoding) |
| 47 | +format (supported by most TON libraries) |
| 48 | + |
| 49 | +The `evm_recipient` must be the address of a universal app contract. |
| 50 | + |
| 51 | +The `call_data` cell contains the payload that will be passed to the `onCall` |
| 52 | +function of the universal app contract. |
| 53 | + |
| 54 | +Here's an example of how to construct the deposit-and-call message in |
| 55 | +TypeScript: |
| 56 | + |
| 57 | +```typescript |
| 58 | +const opDepositAndCall = 102; |
| 59 | +const body = beginCell() |
| 60 | + .storeUint(opDepositAndCall, 32) |
| 61 | + .storeUint(0, 64) |
| 62 | + .storeUint(zevmRecipient, 160) |
| 63 | + .storeRef(callDataCell) // callDataCell should be a cell containing the payload |
| 64 | + .endCell(); |
| 65 | +``` |
| 66 | + |
| 67 | +After the cross-chain transaction is processed, the `onCall` function of the |
| 68 | +universal app contract is executed. |
0 commit comments