-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ts
50 lines (43 loc) · 1.73 KB
/
main.ts
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
48
49
50
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, internal } from "ton";
async function main() {
// open wallet v4 (notice the correct wallet version here)
const mnemonic = "unfold sugar water ..."; // your 24 secret words (replace ... with the rest of the words)
const key = await mnemonicToWalletKey(mnemonic.split(" "));
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
// make sure wallet is deployed
if (!await client.isContractDeployed(wallet.address)) {
return console.log("wallet is not deployed");
}
// send 0.05 TON to EQA4V9tF4lY2S_J-sEQR7aUj9IwW-Ou2vJQlCn--2DLOLR5e
const walletContract = client.open(wallet);
const seqno = await walletContract.getSeqno();
await walletContract.sendTransfer({
secretKey: key.secretKey,
seqno: seqno,
messages: [
internal({
to: "EQA4V9tF4lY2S_J-sEQR7aUj9IwW-Ou2vJQlCn--2DLOLR5e",
value: "0.05", // 0.05 TON
body: "Hello", // optional comment
bounce: false,
})
]
});
// wait until confirmed
let currentSeqno = seqno;
while (currentSeqno == seqno) {
console.log("waiting for transaction to confirm...");
await sleep(1500);
currentSeqno = await walletContract.getSeqno();
}
console.log("transaction confirmed!");
}
main();
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}