I'm trying to sign and send a mina transaction on devnet and it fails with this message.
error - Error: Query failed -- returned code 200. mutation($from:PublicKey!, $to:PublicKey!, $amount:UInt64!, $fee:UInt64!, $memo:String, $scalar:String, $field:String, $nonce:UInt32){ sendPayment(input: { from:$from, to:$to, amount:$amount, fee:$fee, memo:$memo, nonce:$nonce }, signature:{ scalar: $scalar, field: $field, }) { payment { amount fee feePayer { publicKey token } feeToken from fromAccount { publicKey token } hash id isDelegation kind memo nonce receiver { publicKey token } source { publicKey token } to token toAccount { token publicKey } } } } | {'data': None, 'errors': [{'message': 'Couldn\'t send user_command: Error creating user command: {"payload":{"common":{"fee":"0.01","fee_token":"1","fee_payer_pk":"B62qqAMY1gz8kvEAyf1ioBLPCfbq8WqpLqGXTqUF9LBVf4HLSTXTnMb","nonce":"0","valid_until":"4294967295","memo":"E4YM2vTHhWEg66xpj52JErHUBU4pZ1yageL4TVDDpTTSsv8mK6YaH"},"body":["Payment",{"source_pk":"B62qqAMY1gz8kvEAyf1ioBLPCfbq8WqpLqGXTqUF9LBVf4HLSTXTnMb","receiver_pk":"B62qop7Eh2nAymEun27TJYhKA1rWyvGHgHGwFpQDF1ANhFt2zCqsVFU","token_id":"1","amount":"1"}]},"signer":"B62qqAMY1gz8kvEAyf1ioBLPCfbq8WqpLqGXTqUF9LBVf4HLSTXTnMb","signature":["Signature","7mX8NLNR3mWuEV7QvQi5Z7yEfJn13y3KNS9BBHo9B31UuMhzBm9G3jKKMXpMY1Lr6obrP9BfP92KfVxDfsoBwiDV93kT17Lg"]} Error: Invalid_signature', 'locations': [{'line': 1, 'column': 136}], 'path': ['sendPayment']}]}
This is the transfer function and it fails at when I send it to /broadcast/tx
endpoint fetch...
call.
Thank you.
const transfer2 = async (sender: string, receiver: string, amount: number) => {
...
let signedPayment = MinaSDK.signPayment({
to: receiver,
from: sender,
amount: 1,
fee: 10000000,
nonce: json.account.nonce
}, keys);
res = await fetch(process.env.MINA_REST_URL! + '/broadcast/transaction', {
method: 'POST',
body: JSON.stringify(signedPayment),
headers: {
'Content-Type': 'application/json',
},
})
json = await res.json()
if (res.status !== 200) {
throw new Error(json.error)
}
return json
}
I found the problem, and for further reference there is the transfer function, I used to send MINA on devnet.
const minaGqlClient = new GraphQLClient(process.env.MINA_GRAPHQL_URL!)
// MINA_GRAPHQL_URL="https://devnet.graphql.minaexplorer.com/"
const transfer = async (sender: string, receiver: string, _amount: number) => {
let amount = new BigNumber(_amount).multipliedBy(1000000000).toFixed(0)
// get account details
let res = await fetch(process.env.MINA_REST_URL! + '/accounts/' + sender)
let json = await res.json()
let keys = {
publicKey: process.env.MINA_GAME_WALLET_PUBLIC_KEY!,
privateKey: process.env.MINA_GAME_WALLET_PRIVATE_KEY!,
}
let signedPayment = minaSignerClient.signPayment({
to: receiver,
from: sender,
amount: amount,
fee: BigNumber("0.06").multipliedBy(1000000000).toString(),
nonce: json.account.nonce,
}, keys.privateKey)
const isPaymentVerified = minaSignerClient.verifyPayment(signedPayment)
if (!isPaymentVerified) {
throw new Error("Payment signature is not valid")
}
json = {
...signedPayment,
payload: signedPayment.data,
}
delete json.data
console.info("Signed payment: ", JSON.stringify(signedPayment, null, 2))
res = await fetch(process.env.MINA_REST_URL! + '/broadcast/transaction', {
method: 'POST',
body: JSON.stringify(json),
headers: {
'Content-Type': 'application/json',
},
})
json = await res.json()
if (res.status != 201) {
throw new Error(json.error)
}
return json
}