Skip to content

Instantly share code, notes, and snippets.

@w3kim
Created October 28, 2019 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w3kim/6ba9c025988b61d9a4b9808017741f40 to your computer and use it in GitHub Desktop.
Save w3kim/6ba9c025988b61d9a4b9808017741f40 to your computer and use it in GitHub Desktop.
Sending Multiple VT Transactions with Modified Nonce
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