Skip to content

Commit ad73551

Browse files
fadeevswift1337
andauthored
Ton Gateway (#588)
Co-authored-by: Dmitry S <11892559+swift1337@users.noreply.github.com>
1 parent 0aaf72e commit ad73551

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

src/pages/developers/chains/_meta.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
},
1818
"solana": {
1919
"title": "Solana",
20-
"description": "Make calls to universal apps and deposit tokens from Solana"
20+
"description": "Make calls to universal apps and deposit from Solana"
21+
},
22+
"ton": {
23+
"title": "Ton",
24+
"description": "Make calls to universal apps and deposit from TON"
2125
},
2226
"sui": {
2327
"title": "Sui",

src/pages/developers/chains/evm.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ universal contract and passes the `payload` as the `message` parameter.
121121

122122
The `call` function doesn't support revert handling. If
123123
`revertOptions.callOnRevert` is set to `true`, the transaction will fail. This
124-
is because executing a contract call on revert requires tokens to cover gas
125-
fees on ZetaChain, and the `call` function doesn't transfer any assets. If you
126-
need to handle reverts, use `depositAndCall` instead and ensure sufficient
127-
tokens are deposited to cover potential gas fees.
124+
is because executing a contract call on revert requires tokens to cover gas fees
125+
on ZetaChain, and the `call` function doesn't transfer any assets. If you need
126+
to handle reverts, use `depositAndCall` instead and ensure sufficient tokens are
127+
deposited to cover potential gas fees.
128128

129129
## Revert Transactions
130130

src/pages/developers/chains/ton.mdx

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)