Error while calling /decode-calldata/source

Hey people,

I’m trying to decode call data of an arbitrary transaction using this api .

My attempt fails with error code 500. I tried with both public testnet+latestCompiler, and local nodes+compiler with the same results. I also tried using js-sdk versions 5.0 and 6.0.

Here’s an example together with output, hope someone can help - not sure if using API as intended.

ExampleContract.aes

contract Example =

    record state = { number : int }

    stateful entrypoint init() : state = { number = 42 }

    stateful entrypoint set_number(num: int) =
        put(state{ number = num })

Test file

const fs = require('fs')
const path = require('path')
const { Universal, TxBuilder } = require('@aeternity/aepp-sdk')

describe('Playground', function () {

    it('will fail to decode', async () => {

        let client = await Universal({
            url: "https://sdk-testnet.aepps.com",
            internalUrl: "https://sdk-testnet.aepps.com",
            keypair: {
                publicKey: 'ak_fUq2NesPXcYZ1CcqBcGC3StpdnQw3iVxMA3YSeCNAwfN4myQk',
                secretKey: '7c6e602a94f30e4ea7edabe4376314f69ba7eaa2f355ecedb339df847b6f0d80575f81ffb0a297b7725dc671da0b1769b1fc5cbe45385c7b5ad1fc2eaf1d609d'
            },
            compilerUrl: 'http://latest.compiler.aepps.com'
        })

        let source = fs.readFileSync(path.join(__dirname, '..', 'contracts', 'Example.aes')).toString() 
        let instance = await client.getContractInstance(source)
        
        await instance.deploy()
        
        let call = await instance.methods.set_number(11)

        let unpackedTx = (await TxBuilder.unpackTx(call.rawTx)).tx.encodedTx.tx
        console.log("unpacked tx", unpackedTx)
        
        let callData = unpackedTx.callData
        console.log(`Attempt to decode callData ${callData}`)

        let callDataDecoded = await client.contractDecodeCallDataBySourceAPI(
            source, 
            'set_number', 
            callData, 
            { backend : 'fate' }
        )
        console.log("callDataDecoded", callDataDecoded)

    })
})

And finally output when running this test:

  Playground
unpacked tx { tag: '43',
  VSN: '1',
  callerId: 'ak_fUq2NesPXcYZ1CcqBcGC3StpdnQw3iVxMA3YSeCNAwfN4myQk',
  nonce: '318',
  contractId: 'ct_2oJmzXbz3cBijNCssgZ7LADnKRJJneMqo1ewqgzhzev7MX3qR8',
  abiVersion: '3',
  fee: '452080000000000',
  ttl: '0',
  amount: '0',
  gas: '1579000',
  gasPrice: '1000000000',
  callData: 'cb_KxF+1YUSGxbDJWMI' }
Attempt to decode callData cb_KxF+1YUSGxbDJWMI
    1) will fail to decode


  0 passing (17s)
  1 failing

  1) Playground
       will fail to decode:
     Error: Http request for http://latest.compiler.aepps.com/decode-calldata/source failed with status code 500. Status: Internal Server Error. 
Error data: ""
      at node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:151993
      at u (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:17480)
      at Generator._invoke (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:17268)
      at Generator.forEach.t.(anonymous function) [as throw] (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:17903)
      at n (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2196)
      at s (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2443)
      at process._tickCallback (internal/process/next_tick.js:68:7)



npm ERR! Test failed.  See above for more details.

Thanks

I think you should use { backend : 'aevm' } option unless you compiled the contract with fate backend.

I compiled the contract with fate backend. But never mind, I found that .contractDecodeCallDataByCodeAPI(bytecode, callData, "fate") works as expected so I’m just gonna use that. Thanks :+1: