@@ -855,7 +855,7 @@ Smart contracts for collections allow deploying up to 250 NFTs in a single trans
855
855
#### Batch mint NFT
856
856
:::info
857
857
Does not specified by NFT standard for /ton-blockchain /token-contract
858
- :::
858
+ :::
859
859
<br ></br >
860
860
<div class = " text--center" >
861
861
<ThemedImage
@@ -1490,7 +1490,7 @@ async def main():
1490
1490
stack = [pool_type , asset_native , asset_jetton ]
1491
1491
)
1492
1492
pool_address = stack [0 ].load_address ()
1493
-
1493
+
1494
1494
swap_params = (begin_cell ()
1495
1495
.store_uint (int (time .time () + 60 * 5 ), 32 ) # Deadline
1496
1496
.store_address (wallet .address ) # Recipient address
@@ -1512,7 +1512,7 @@ async def main():
1512
1512
await wallet .transfer (destination = DEDUST_NATIVE_VAULT ,
1513
1513
amount = TON_AMOUNT + GAS_AMOUNT , # swap amount + gas
1514
1514
body = swap_body )
1515
-
1515
+
1516
1516
await provider .close_all ()
1517
1517
1518
1518
asyncio .run (main ())
@@ -1521,7 +1521,7 @@ asyncio.run(main())
1521
1521
</TabItem>
1522
1522
</Tabs>
1523
1523
1524
- ## Basics of incoming message processing
1524
+ ## Basics of message processing
1525
1525
1526
1526
### How to parse transactions of an account (Transfers, Jettons, NFTs)?
1527
1527
@@ -1703,17 +1703,17 @@ async def parse_transactions(transactions):
1703
1703
value = transaction .in_msg .info .value_coins
1704
1704
if value != 0 :
1705
1705
value = value / 1e9
1706
-
1706
+
1707
1707
if len (transaction .in_msg .body .bits ) < 32 :
1708
1708
print (f " TON transfer from {sender} with value {value} TON" )
1709
1709
else :
1710
1710
body_slice = transaction .in_msg .body .begin_parse ()
1711
1711
op_code = body_slice .load_uint (32 )
1712
-
1712
+
1713
1713
# TextComment
1714
1714
if op_code == 0 :
1715
1715
print (f " TON transfer from {sender} with value {value} TON and comment: {body_slice.load_snake_string()}" )
1716
-
1716
+
1717
1717
# Jetton Transfer Notification
1718
1718
elif op_code == 0x7362d09c :
1719
1719
body_slice .load_bits (64 ) # skip query_id
@@ -1723,7 +1723,7 @@ async def parse_transactions(transactions):
1723
1723
forward_payload = body_slice .load_ref ().begin_parse ()
1724
1724
else :
1725
1725
forward_payload = body_slice
1726
-
1726
+
1727
1727
jetton_master = (await provider .run_get_method (address = sender , method = " get_wallet_data" , stack = []))[2 ].load_address ()
1728
1728
jetton_wallet = (await provider .run_get_method (address = jetton_master , method = " get_wallet_address" ,
1729
1729
stack = [
@@ -1733,7 +1733,7 @@ async def parse_transactions(transactions):
1733
1733
if jetton_wallet != sender :
1734
1734
print (" FAKE Jetton Transfer" )
1735
1735
continue
1736
-
1736
+
1737
1737
if len (forward_payload .bits ) < 32 :
1738
1738
print (f " Jetton transfer from {jetton_sender} with value {jetton_amount} Jetton" )
1739
1739
else :
@@ -1742,7 +1742,7 @@ async def parse_transactions(transactions):
1742
1742
print (f " Jetton transfer from {jetton_sender} with value {jetton_amount} Jetton and comment: {forward_payload.load_snake_string()}" )
1743
1743
else :
1744
1744
print (f " Jetton transfer from {jetton_sender} with value {jetton_amount} Jetton and unknown payload: {forward_payload} " )
1745
-
1745
+
1746
1746
# NFT Transfer Notification
1747
1747
elif op_code == 0x05138d91 :
1748
1748
body_slice .load_bits (64 ) # skip query_id
@@ -1825,7 +1825,7 @@ export async function retry<T>(fn: () => Promise<T>, options: { retries: number,
1825
1825
1826
1826
` ` `
1827
1827
1828
- Create listener function which will assert specific transaction on certain account with specific incoming external message, equal to body message in boc:
1828
+ Create listener function which will assert specific transaction on certain account with specific incoming external message, equal to body message in boc:
1829
1829
1830
1830
<Tabs>
1831
1831
<TabItem value="ts" label="@ton/ton">
@@ -1883,10 +1883,83 @@ export async function getTxByBOC(exBoc: string): Promise<string> {
1883
1883
1884
1884
txRes = getTxByBOC (exBOC );
1885
1885
console .log (txRes );
1886
-
1887
-
1888
1886
` ` `
1889
1887
1890
1888
</TabItem>
1891
1889
1892
- </Tabs>
1890
+ </Tabs>
1891
+
1892
+ ### How to find transaction or message hash?
1893
+
1894
+ :::info
1895
+ Be careful with the hash definition. It can be either a transaction hash or a message hash. These are different things.
1896
+ :::
1897
+
1898
+ To get transaction hash you need to use ` hash ` method of a transaction. To get external message hash you need
1899
+ to build message cell using ` storeMessage ` method and then use ` hash ` method of this cell.
1900
+
1901
+ <Tabs>
1902
+ <TabItem value="ts" label="@ton/ton">
1903
+
1904
+ ` ` ` typescript
1905
+ import { storeMessage , TonClient } from ' @ton/ton' ;
1906
+ import { Address , beginCell } from ' @ton/core' ;
1907
+
1908
+ const tonClient = new TonClient ({ endpoint: ' https://testnet.toncenter.com/api/v2/jsonRPC' });
1909
+
1910
+ const transactions = await tonClient .getTransactions (Address .parse (' [ADDRESS]' ), { limit: 10 });
1911
+ for (const transaction of transactions ) {
1912
+ // ful transaction hash
1913
+ const transactionHash = transaction .hash ();
1914
+
1915
+ const inMessage = transaction .inMessage ;
1916
+ if (inMessage ? .info.type === ' external-in' ) {
1917
+ const inMessageCell = beginCell ().store (storeMessage (inMessage )).endCell ();
1918
+ // external-in message hash
1919
+ const inMessageHash = inMessageCell .hash ();
1920
+ }
1921
+
1922
+ // also you can get hash of out messages if needed
1923
+ for (const outMessage of transaction.outMessages.values()) {
1924
+ const outMessageCell = beginCell ().store (storeMessage (outMessage )).endCell ();
1925
+ const outMessageHash = outMessageCell .hash ();
1926
+ }
1927
+ }
1928
+ ` ` `
1929
+
1930
+ </TabItem>
1931
+
1932
+ </Tabs>
1933
+
1934
+ Also you can get hash of message when building it. Note, this is the same hash as the hash of the message sent to initiate transaction
1935
+ like in previous example.
1936
+
1937
+ <Tabs>
1938
+ <TabItem value="ts" label="@ton/ton">
1939
+
1940
+ ` ` ` typescript
1941
+ import { mnemonicNew , mnemonicToPrivateKey } from ' @ton/crypto' ;
1942
+ import { internal , TonClient , WalletContractV4 } from ' @ton/ton' ;
1943
+ import { toNano } from ' @ton/core' ;
1944
+
1945
+ const tonClient = new TonClient ({ endpoint: ' https://testnet.toncenter.com/api/v2/jsonRPC' });
1946
+
1947
+ const mnemonic = await mnemonicNew ();
1948
+ const keyPair = await mnemonicToPrivateKey (mnemonic );
1949
+ const wallet = tonClient .open (WalletContractV4 .create ({ publicKey: keyPair .publicKey , workchain: 0 }));
1950
+ const transfer = await wallet .createTransfer ({
1951
+ secretKey: keyPair .secretKey ,
1952
+ seqno: 0 ,
1953
+ messages: [
1954
+ internal ({
1955
+ to: wallet .address ,
1956
+ value: toNano (1 )
1957
+ })
1958
+ ]
1959
+ });
1960
+ const inMessageHash = transfer .hash ();
1961
+ ` ` `
1962
+
1963
+ </TabItem>
1964
+
1965
+ </Tabs>
0 commit comments