Created
September 26, 2019 08:12
-
-
Save webmaster128/97fd77bf5d38cb73ffc656e87e5dbe32 to your computer and use it in GitHub Desktop.
Send send transactions to Babynet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const transactionsCount = 100; | |
| const nodeUrl = "wss://rpc-private-a-vip-babynet.iov.one"; | |
| const mnemonic = "twin document gold guide asset false rival rib civil squeeze they upper"; | |
| const profile = new UserProfile(); | |
| const signer = new MultiChainSigner(profile); | |
| const { connection } = await signer.addChain(createBnsConnector(nodeUrl)); | |
| const chainId = connection.chainId(); | |
| const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic(mnemonic)); | |
| // any identity that can pay the fees | |
| const friend = await profile.createIdentity(wallet.id, chainId, HdPaths.iov(0)); | |
| const friendAddress = signer.identityToAddress(friend); | |
| console.log("Sender address", friendAddress); | |
| const recipient = `tiov1l2lffvk5eu482yug3agphwfd0sgtv0r5pp49vl` as Address; | |
| for (let i = 0; i < transactionsCount; i++) { | |
| console.log("Creating tx", i + 1); | |
| const tx = await connection.withDefaultFee<SendTransaction & WithCreator>({ | |
| kind: "bcp/send", | |
| creator: friend, | |
| sender: friendAddress, | |
| recipient: recipient, | |
| amount: { | |
| quantity: "1", | |
| fractionalDigits: 9, | |
| tokenTicker: "IOV" as TokenTicker, | |
| }, | |
| }); | |
| const startTime = Date.now(); | |
| const postResult = await signer.signAndPost(tx); | |
| const postedTime = Date.now(); | |
| console.log("Time to node", ((postedTime - startTime) / 1000).toFixed(3)); | |
| const blockInfo = await postResult.blockInfo.waitFor(info => !isBlockInfoPending(info)); | |
| if (!isBlockInfoSucceeded(blockInfo)) { | |
| throw new Error("Transaction failed"); | |
| } | |
| const blockTime = Date.now(); | |
| console.log("Time to block", ((blockTime - startTime) / 1000).toFixed(3)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment