Skip to content

Commit b8334ad

Browse files
pixelplexvkokosh
andauthored
Added an example of how to send a transaction with Wallet V5 (#721)
Co-authored-by: Vladislav Kokosh <v.kokosh@pixelplex.io>
1 parent 9c6f6f1 commit b8334ad

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

docs/develop/dapps/cookbook.mdx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,15 @@ Most SDKs provide the following process for sending messages from your wallet:
311311
- After that, you can form messages you want and send them. You can also send up to 4 messages per request, as described in an [advanced manual](/develop/smart-contracts/tutorials/wallet#sending-multiple-messages-simultaneously).
312312

313313
<Tabs groupId="code-examples">
314-
<TabItem value="js-ton" label="JS (@ton)">
314+
<TabItem value="js-ton-v4" label="JS (@ton) for Wallet V4">
315315

316316
```js
317317
import { TonClient, WalletContractV4, internal } from "@ton/ton";
318318
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
319319

320320
const client = new TonClient({
321321
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
322+
apiKey: 'your-api-key', // Optional, but note that without api-key you need to send requests once per second, and with 0.25 seconds
322323
});
323324

324325
// Convert mnemonics to private key
@@ -345,6 +346,46 @@ await contract.sendTransfer({
345346

346347
</TabItem>
347348

349+
<TabItem value="js-ton-v5" label="JS (@ton) for Wallet V5">
350+
351+
```js
352+
import { TonClient, WalletContractV5R1, internal, SendMode } from "@ton/ton";
353+
import { mnemonicToPrivateKey } from "@ton/crypto";
354+
355+
const client = new TonClient({
356+
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
357+
apiKey: 'your-api-key', // Optional, but note that without api-key you need to send requests once per second, and with 0.25 seconds
358+
});
359+
360+
// Convert mnemonics to private key
361+
let mnemonics = "word1 word2 ...".split(" ");
362+
let keyPair = await mnemonicToPrivateKey(mnemonics);
363+
364+
// Create wallet contract
365+
let wallet = WalletContractV5R1.create({
366+
publicKey: keyPair.publicKey,
367+
workChain: 0, // Usually you need a workchain 0
368+
});
369+
let contract = client.open(wallet);
370+
371+
// Create a transfer
372+
let seqno: number = await contract.getSeqno();
373+
await contract.sendTransfer({
374+
secretKey: keyPair.secretKey,
375+
seqno,
376+
sendMode: SendMode.PAY_GAS_SEPARATELY,
377+
messages: [
378+
internal({
379+
to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
380+
value: '0.05',
381+
body: 'Example transfer body',
382+
}),
383+
],
384+
});
385+
```
386+
387+
</TabItem>
388+
348389
<TabItem value="ton-kotlin" label="ton-kotlin">
349390

350391
```kotlin

0 commit comments

Comments
 (0)