-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c9b28e
commit ec0c792
Showing
1 changed file
with
48 additions
and
46 deletions.
There are no files selected for viewing
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
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)); | ||
} |