Skip to content

Commit

Permalink
Enforce mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmarcou committed May 3, 2024
1 parent 5c9b28e commit ec0c792
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions src/paymentGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
import Client from 'mina-signer';

export async function processTransaction(
network: string,
deployerAccount: string,
receiver: string,
timeDelayMS: number,
amount: number,
fee: number
network: string,
deployerAccount: string,
receiver: string,
timeDelayMS: number,
amount: number,
fee: number
) {
const client = new Client({ network: 'testnet' });
let sender_public = client.derivePublicKey(deployerAccount)
console.log("receiver: ", receiver);
let amountToSend = amount * 1000000000;
let feeToSend = fee * 1000000000;
const query = `query MyQuery {
const client = new Client({ network: 'mainnet' });
let sender_public = client.derivePublicKey(deployerAccount);
console.log('receiver: ', receiver);
let amountToSend = amount * 1000000000;
let feeToSend = fee * 1000000000;
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)
let signedPayment = client.signPayment(
{
to: receiver,
from: sender_public,
amount: amountToSend,
fee: feeToSend,
nonce: inferred_nonce
},
deployerAccount
);
const query_pay = `mutation MyMutation {
}`;
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
);
let signedPayment = client.signPayment(
{
to: receiver,
from: sender_public,
amount: amountToSend,
fee: feeToSend,
nonce: inferred_nonce,
},
deployerAccount
);
const query_pay = `mutation MyMutation {
sendPayment(input: {fee: "${feeToSend}", amount: "${amountToSend}", to: "${receiver}", from: "${sender_public}", nonce: "${inferred_nonce}"}, signature: {field: "${signedPayment.signature.field}", scalar: "${signedPayment.signature.scalar}"})}`;
await fetch(network, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query: query_pay
}),
})
.then(r => r.json())
.then(data => console.log("data returned:", data));
await new Promise(r => setTimeout(r, timeDelayMS));
await fetch(network, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: query_pay,
}),
})
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
await new Promise((r) => setTimeout(r, timeDelayMS));
}

0 comments on commit ec0c792

Please sign in to comment.