-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hash.js
47 lines (41 loc) · 1.39 KB
/
test_hash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { TonClient, NetworkQueriesProtocol } = require('@eversdk/core')
const { libNode } = require('@eversdk/lib-node')
const { Account } = require('@eversdk/appkit')
const GoshABI = require('./abis/gosh.abi.json')
const ENDPOINTS = ['https://vps23.ton.dev']
TonClient.useBinaryLibrary(libNode)
const client = new TonClient({
network: {
endpoints: ENDPOINTS,
queries_protocol: NetworkQueriesProtocol.WS,
sending_endpoint_count: ENDPOINTS.length,
message_retries_count: 0,
},
})
const testTvmHash = async () => {
// Prepare data as bytes
const data = Buffer.from('Test data').toString('hex')
// Run contract getter
const gosh = new Account(
{ abi: GoshABI },
{
client,
address: '0:870d2c26cf3cbfcac7e853e687b1bd6499584184af34a093ac34384b273a7a02',
},
)
const result = await gosh.runLocal('getHash', { state: data })
console.log(`TMV hash by getter\t${result.decoded.output.value0}`)
// Get hash by SDK
const { boc } = await client.abi.encode_boc({
params: [{ name: 'state', type: 'bytes' }],
data: { state: data },
})
const { hash } = await client.boc.get_boc_hash({ boc })
console.log(`TVM hash by SDK\t\t0x${hash}`)
}
testTvmHash()
.then(() => process.exit(0))
.catch((reason) => {
console.log('Error', reason.message)
process.exit(-1)
})