Created
October 28, 2019 05:24
-
-
Save w3kim/6ba9c025988b61d9a4b9808017741f40 to your computer and use it in GitHub Desktop.
Sending Multiple VT Transactions with Modified Nonce
This file contains 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 Caver = require('caver-js') | |
const caver = new Caver('https://api.baobab.klaytn.net:8651') | |
const sender = caver.klay.accounts.wallet.add('your_private_key'); | |
const recipient = 'recipient_address'; | |
const x = async () => { | |
const account = await caver.klay.getAccount(sender.address); | |
const startingNonce = account.account.nonce; | |
console.log(startingNonce); | |
const since = new Date(); | |
console.log(since); | |
for (var i = 0; i < 10; i++) { | |
caver.klay.sendTransaction({ | |
nonce: startingNonce + i, | |
type: 'VALUE_TRANSFER', | |
from: sender.address, | |
to: recipient, | |
gas: '300000', | |
value: caver.utils.toPeb('0.1', 'KLAY') | |
}) | |
.on('transactionHash', function (hash) { | |
console.log('hash -> ', hash) | |
}) | |
.on('receipt', function (receipt) { | |
caver.klay.getAccount(sender.address).then((v) => { | |
console.log(v.account.nonce); | |
}); | |
}) | |
.on('error', console.error); | |
} | |
const now = new Date(); | |
console.log(now - since + ' ms'); | |
}; | |
x(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment