Unanswered
In JavaScript, you can use the ton
package. I have adapted an example from a community-led TON tutorial. Please use at your own risk.
What it does is:
- Generate multiple mnemonics
- Find the addresses of the generated mnemonics
- Fund the addresses of these mnemonics with a pre-funded wallet
- Send a transaction out of these mnemonnics to automatically deploy the contract
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey, mnemonicNew } from "ton-crypto";
import { TonClient, WalletContractV4, internal } from "ton";
async function main() {
// open wallet v4 (set your correct wallet version here)
const mnemonic = "unfold sugar water ..."; // insert a mnemonic for a wallet that has funds
const key = await mnemonicToWalletKey(mnemonic.split(" "));
const fundingWallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });
for(let i = 0; i < 5; i++) {
let m = await mnemonicNew();
console.log(m);
await initializeWallet(fundingWallet, m);
}
}
async function initializeWallet(fundingWallet: WalletContractV4, mnemonic: string[]) {
// open wallet v4 (notice the correct wallet version here)
const key = await mnemonicToWalletKey(mnemonic);
const generatedWallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
// send 0.1 TON from funding wallet to new wallet
let walletContract = client.open(generatedWallet);
let seqno = await walletContract.getSeqno();
await walletContract.sendTransfer({
secretKey: key.secretKey,
seqno: seqno,
messages: [
internal({
to: generatedWallet.address,
value: "0.09", // 0.001 TON
bounce: false,
})
]
});
// send 0.9 back TON to funding wallet
walletContract = client.open(generatedWallet);
seqno = await walletContract.getSeqno();
await walletContract.sendTransfer({
secretKey: key.secretKey,
seqno: seqno,
messages: [
internal({
to: fundingWallet.address,
value: "0.09", // 0.001 TON
bounce: false
})
]
});
await waitForTransaction(seqno, walletContract);
}
async function waitForTransaction(seqno: number, walletContract: any) {
// 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!");
}
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
main();
1K Views
0
Answers
one year ago
one year ago
nice nice
Tell me please. How I can get transaction hash after sendTransfer ?
Won't work.
// This will try to send frome generatedWallet to generatedWallet, you need to open fundingwallet instead and use its key.