[Solved] Cannot send manually created transaction

Hi everyone,

I am trying to manually create contract call transaction, sign it, and then broadcast. Issue appears in the final step (send signed tx). I’m using [email protected] (js) and [email protected]. This is the procedure:

  1. initialize client
let client = await Ae({
        url: "http://localhost:3001/",
        internalUrl: "http://localhost:3001/internal/",
        keypair: wallets[0],
        nativeMode: true,
        networkId: 'ae_devnet',
        compilerUrl: 'http://localhost:3080'
})
  1. Create transaction
let tx = await client.contractCallTx({
        callerId :'ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU',
        contractId : 'ct_2CGgcDvUarBGf5KFDArvCkVh4Pnj3NgWCYB2LY6Aw8Km4WPhtc',
        abiVersion : 1,
        amount : 0,
        gas : 10000000,
        callData : 'cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBBy0//B8qHRJKsGwguR3V9heRWcHkjlDwi4abi8PuBJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgdPWP66dSrgQm7L7joxQU2OazM11k7EFvPldOEGx+VBKGocxj'
})

Contract with given ID actually exists and is deployed on private network running locally (forgae node). Caller account matches the keypair provided when initializing client. Call data is encoded using local sophia_http compiler.

  1. Sign and send
let signedTx = await client.signTransaction(tx)
console.log("signed tx", signedTx)

let result = await client.sendTransaction(signedTx, { verifiy: true }).catch(console.log)

This is the error output after sendTransaction() is called:

{ Error: While calling postTransaction (body), POST to http://localhost:3001/v2/transactions failed with 400: Invalid tx
    at Object.<anonymous> (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:61641)
    at w (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:140792)
    at Generator._invoke (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:140580)
    at Generator.e.(anonymous function) [as throw] (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:140971)
    at n (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2527)
    at c (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2773)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
  rawTx:
   'tx_+QEnCwH4QrhAe0H/B+RDLkzUAH0QTecyQhnd5ryVfDe0J75m65KoxYkWzHMmqGfME4+dwp31XOvCGhb8qF5W1hyZZev5QW5YCLjf+N0rAaEB6bv2BOYRtUYKOzmZ6Xcbb2BBfXPOfFUZ4S9+EnoSJcoZoQWdSXKZeBDTABqMFdpF3Bz5XKyRboumgBtonBjsIwMldwGHJSRGpp5YAAAAg5iWgIQ7msoAuIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIEHLT/8HyodEkqwbCC5HdX2F5FZweSOUPCLhpuLw+4EkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGB09Y/rp1KuBCbsvuOjFBTY5rMzXWTsQW8+V04QbH5UEvZHpIU=',
  verifyTx: [Function: verifyTx] }

Here are unsigned and signed transactions:

//unsigned
tx_+N0rAaEB6bv2BOYRtUYKOzmZ6Xcbb2BBfXPOfFUZ4S9+EnoSJcoZoQWdSXKZeBDTABqMFdpF3Bz5XKyRboumgBtonBjsIwMldwGHJSRGpp5YAAAAg5iWgIQ7msoAuIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIEHLT/8HyodEkqwbCC5HdX2F5FZweSOUPCLhpuLw+4EkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGB09Y/rp1KuBCbsvuOjFBTY5rMzXWTsQW8+V04QbH5UEmGHNXQ=

//signed
tx_+QEnCwH4QrhAe0H/B+RDLkzUAH0QTecyQhnd5ryVfDe0J75m65KoxYkWzHMmqGfME4+dwp31XOvCGhb8qF5W1hyZZev5QW5YCLjf+N0rAaEB6bv2BOYRtUYKOzmZ6Xcbb2BBfXPOfFUZ4S9+EnoSJcoZoQWdSXKZeBDTABqMFdpF3Bz5XKyRboumgBtonBjsIwMldwGHJSRGpp5YAAAAg5iWgIQ7msoAuIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIEHLT/8HyodEkqwbCC5HdX2F5FZweSOUPCLhpuLw+4EkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGB09Y/rp1KuBCbsvuOjFBTY5rMzXWTsQW8+V04QbH5UEvZHpIU=
1 Like

Did you try using the updated forgae and js-sdk? Also it could be beneficial to use the higher level contract interface using getContractInstance.

2 Likes

Apparently I was manually creating transaction with ownerId field set on first value of accounts generated by forgae node command. Then I was signing transaction within tests using wallets[0] keypair which is not first generated account but second (first one is actually miner). Therefore, signature was invalid.

3 Likes

Hey @filip,
As i see you are using local node maybe the reason why is signature invalid is network_id?
Try to remove network_id prop from sdk initialization and let sdk retrieve network_id itself(using node API)

Thanks for suggestion but network_id was fine. That was actually first thing that crossed my mind. The problem was I was creating transaction with accountX, and trying to sign it using keys of accountY. So the transaction could not be processed since signature could not be verified.

1 Like