[Solved] Sophia compiler - error encoding call data

I’m having trouble calling /encode-calldata endpoint on my local sophia-compiler. I use [email protected] which boots up aesophia_http:v2.1.0 docker image when starting local Ae nodes.

let response = await axios.post(`${config.compiler.host}/encode-calldata`, {
         "function" : "add_wallet",
         "arguments" : [ wallet ],
         "source" : coopSource
}).catch(function(error) {
         console.log(error)
})

The error I get is 403 Forbidden with following description:

Type errors\nUnbound variable ak_FHZrEbRmanKUe9ECPXVNTLLpRP2SeQCLCT6Vnvs9JuVu78J7V at line 53, column 36\n

The address in this error message is actually the one I’m trying to encode (wallet variable in example code above). coopSource is the full source code of contract containing add_wallet() function.

Contract compiles successfully (tried with forgae compile). Also no problems with deployment.

Here’s the function:

public stateful function add_wallet(wallet: address) =
    only_owner()
    put(state{ activeWallets[wallet] = true })
1 Like

If you want to use the “new” style for literals you need to use a later version of the compiler. Currently the latest released version is 3.1.0.

2 Likes

Thanks, I’ve updated compiler version but now my deployment script fails :joy:

I have two contracts A and B. B is deployed with address of deployed A as init parameter. This init parameter is not of type address, but AInterface which is my interface over the deployed A contract. I used to provide this parameter in form of address and it worked well. With new compiler, when encode data is called for this init function I get the error:

“Type errors\nCannot unify AInterface\n and bytes(32)”

I understand error message, init function asks for AInterface type and I’m providing address type but I thought these two are interchangeable?

How should I change my code or deploy script for this to work?

AInterface should be a remote contract, not an address. I.e. it should start with ct_

Yes, that’s what I’m providing the init function with. So I don’t see where the issue is unfortunately.

From the error message it sounds as if you are providing something of type bytes(32), i.e. #1a2b3c4d... rather than something of type AInterface, i.e. a contract ct_...

// Deploy

let coop = await coopContract.deploy()
console.log(`Coop deployed at: ${coop.deployInfo.address}`)

let eur = await eurContract.deploy([coop.deployInfo.address])
console.log(`EUR deployed at: ${eur.deployInfo.address}`)

await coop.call('set_token', [eur.deployInfo.address])
console.log('EUR token registered in Coop contract')

Here is my deployment snippet. And this is the output:

Coop deployed at: ct_2WaU6PNKaHeTYhfAGZTz4xdQWPW3aYwa7KQ9aR5gChrRqVbfEu
    1) "before each" hook for "basic test"


  0 passing (8s)
  1 failing

  1) Cooperative contract tests
       "before each" hook for "basic test":
     Error: Http request for http://localhost:3080/encode-calldata failed with status code 403. Status: Forbidden. 
Error data: {"reason":"Type errors\nCannot unify CoopInterface\n         and bytes(32)\nwhen checking the application at line 118, column 32 of\n  init : (CoopInterface) => state\nto arguments\n  #c6dab5c0df33a128b8abf9b803d5c524cda96afdf6da5698f43a381aadda77d2 :\n    bytes(32)\n"}

First line of output is what I pass to init function (ct_2Wa…)

Something in between is destroying it then, when it reaches the call data builder it is #c6dab5c0df33a12...

I’ve never used JavaScript so that part I can’t help with…

2 Likes

Updating the js-sdk to latest version solved the issue.

1 Like