Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Unanswered
How do you create a new TON wallet programmatically?


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:

  1. Generate multiple mnemonics
  2. Find the addresses of the generated mnemonics
  3. Fund the addresses of these mnemonics with a pre-funded wallet
  4. 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();
2
2
Posted one year ago
Edited one year ago
Jeremy
404 × 5 Administrator
  
  

nice nice

Howard   one year ago Report
  
  

Tell me please. How I can get transaction hash after sendTransfer ?

No Name   10 months ago Report
  
  

Won't work.

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,
      })
    ]
  });

// This will try to send frome generatedWallet to generatedWallet, you need to open fundingwallet instead and use its key.

No Name   5 months ago Report
1K Views
0 Answers
one year ago
one year ago