Skip to content

Commit

Permalink
Add i inferred nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
ejMina226 committed Jan 30, 2024
1 parent b26db9a commit e6ad4ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ program
let receivers = fs.readFileSync(walletList).toString().split("\n");

if (transactionType == 'regular') {
if (passwordForSenderPrivateKey == undefined || pathToSenderPrivateKey == undefined) {
console.log('Please provide password and path for key file');
return;
}

paymentGenerator(
url,
Expand Down
19 changes: 17 additions & 2 deletions src/paymentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ export async function paymentGenerator(
) {
const client = new Client({ network: 'testnet' });
let sender_public = client.derivePublicKey(deployerAccount)
const query = `query MyQuery {
account(publicKey: "${sender_public}") {
inferredNonce
}
}`
let response = await fetch(network, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query: query
}),
})
let inferred_nonce = parseInt((await response.json()).data.account.inferredNonce)
for (let i = 0; i < noTransactions; i++) {
const receiver = receivers[Math.floor(Math.random() * receivers.length)]
console.log("receiver: ", receiver)
Expand All @@ -19,12 +34,12 @@ export async function paymentGenerator(
from: sender_public,
amount: 1500000,
fee: 2000000000,
nonce: 0
nonce: inferred_nonce + i
},
deployerAccount
);
const query_pay = `mutation MyMutation {
sendPayment(input: {fee: 2000000000, amount: "1500000", to: "${receiver}", from: "${sender_public}"}, signature: {rawSignature: "${signedPayment.signature}"}) {
sendPayment(input: {fee: 2000000000, nonce: ${inferred_nonce + i}, amount: "1500000", to: "${receiver}", from: "${sender_public}"}, signature: {rawSignature: "${signedPayment.signature}"}) {
}`
await fetch(network, {
method: "POST",
Expand Down

0 comments on commit e6ad4ed

Please sign in to comment.