Contract address as function parameter - failed to encode call data

Hi everyone,

I have a simple function in my contract which accepts single parameter of type address:

stateful entrypoint add_wallet(wallet: address) =
    only_owner()
    put(state{ activeWallets[wallet] = true })

I’m trying to call the function using new ContractInstance API. When I provide address parameter in form of ak_... everything works fine and function is called in regular way. However when I try to pass contract address parameter in form of ct_... I get following error:

Error: Http request for http://localhost:3080/encode-calldata failed with status code 403. Status: Forbidden. 
Error data: {"reason":"Type errors\nThe type address is not a contract type\nwhen checking that the contract literal at line 49, column 47\n  ct_tKBxfzvismpQ9KJsqdcDSH1odMNZSjFMRE6befAWJ6VecC6sT\nhas the type\n  address\n"}
    at node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:125165
    at u (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:16715)
    at Generator._invoke (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:16503)
    at Generator.t.<computed> [as throw] (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:17137)
    at n (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2050)
    at s (node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:1:2296)
    at processTicksAndRejections (internal/process/task_queues.js:89:5) {
  data: {
    reason: 'Type errors\nThe type address is not a contract type\nwhen ' +
      'checking that the contract literal at line 49, column 47\n  ' +
      'ct_tKBxfzvismpQ9KJsqdcDSH1odMNZSjFMRE6befAWJ6VecC6sT\nhas the ' +
      'type\n  address\n'
  }
}

I’m running all the latest versions:
[email protected]
[email protected]
[email protected]

Anyone seen something like this before?

The error message pretty much says it all. A contract ct_... is not an address.

If you want to treat the contract as an address you will need to indicate that by changing ct_ into ak_. This mechanism is there to avoid unintentionally changing the “type” of things.

2 Likes