load testing nearcore payments
const nearlib = require('nearlib'); | |
const { signTransaction, transfer } = nearlib.transactions; | |
const { base_decode } = nearlib.utils.serialize; | |
const sleep = (ms) => new Promise((resolved) => setTimeout(resolved, ms)); | |
(async () => { | |
const [,, accountId, txCount] = process.argv; | |
const near = await nearlib.connect({...require('near-shell/get-config')(), deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore('./neardev') } }); | |
const account = await near.account(accountId); | |
const status = await account.connection.provider.status(); | |
let nonce = account._accessKey.nonce; | |
let transactions = []; | |
for (let i = 0; i < parseInt(txCount); i++) { | |
nonce++; | |
const actions = [transfer(1)]; | |
const [txHash, signedTx] = await signTransaction( | |
accountId, nonce, actions, base_decode(status.sync_info.latest_block_hash), account.connection.signer, account.accountId, account.connection.networkId | |
); | |
transactions.push(signedTx); | |
} | |
console.log('txs', await Promise.all(transactions.map(async (signedTx, i) => { | |
try { | |
await sleep(i); | |
return await account.connection.provider.sendTransaction(signedTx) | |
} catch (e) { | |
console.log('Error: ', e); | |
return null; | |
} | |
}))); | |
})().then(console.log); |
{ | |
"dependencies": { | |
"near-shell": "^0.10.5", | |
"nearlib": "^0.13.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Use like: