[Solved] How to properly encode callData using address as argument?

I’m trying to encode a call data to prepare a createContract argument.
The smart contract initiator should receive an address as parameter.
Using:

addr="ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU"
const callData = await player.contractEncodeCallDataAPI(contract_source, 'init', [addr]);

I get the following error:

Error: Http request for https://compiler.aepps.com/encode-calldata failed with status code 403. 
Status: Forbidden. 
Error data: {"reason":"Type errors\nUnbound variable 
ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU at line 33, column 30\n"}

Using a 32 bytes format, setting

addr="1122334455667788990011223344556677889900112233445566778899001122"

I get the following error:

Error: Http request for https://compiler.aepps.com/encode-calldata failed with status code 403. 
Status: Forbidden. 
Error data: {"reason":"Type errors\nCannot unify address\n         and int\nwhen checking the application at line 33, column 25 of\n  init : (address) => state\nto arguments\n  1122334455667788990011223344556677889900112233445566778899001122 :\n    int\n"}

Using a 32 bytes format with intial chars: “0x”:

addr="0x1122334455667788990011223344556677889900112233445566778899001122"

I get the same error:

Error: Http request for https://compiler.aepps.com/encode-calldata failed with status code 403. Status: Forbidden. 
Error data: {"reason":"Type errors\nCannot unify address\n         and int\nwhen checking the application at line 33, column 25 of\n  init : (address) => state\nto arguments\n  0x1122334455667788990011223344556677889900112233445566778899001122 :\n    int\n"}

Using the addr inside “’”,

addr='"0x1122334455667788990011223344556677889900112233445566778899001122"'

I get the following error:

Error: Http request for https://compiler.aepps.com/encode-calldata failed with status code 403. Status: Forbidden. 

Error data: {“reason”:“Type errors\nCannot unify address\n and string\nwhen checking the application at line 33, column 25 of\n init : (address) => state\nto arguments\n “0x1122334455667788990011223344556677889900112233445566778899001122” :\n string\n”}

Same errors if I use “ak_” instead of “0x” in the address.

1 Like

Maybe you should use something like

addr='#1122334455667788990011223344556677889900112233445566778899001122'

but I still find code using other conventions.

1 Like

That seems to work! Thanks!

The format of address literals has changed, or more precisely is going to change in version 3 of the Sophia compiler. This is already merged in the compiler, but until 3.0 is released (and the network reaches Fortuna hard fork height) it isn’t recommended to use that.

So in v2.X an address is #<hex> (and the same goes for oracles, oracle queries and remote contracts). In v3.X an address is ak_<base58check>, an oracle ok_<base58check>, oracle query oq_<base58check> and a remote contract ct_<base58check>.

4 Likes

Great! @hanssv.chain and how would the formats be in v3.0 and further?

Exactly as I described in my answer?

1 Like

Appologies, I ignored that in the last sentence you talked about version 3.

Hi Hanssv!

We were using v3 addresses before so we can’t understand why it now supports only v2x…

In order to keep using it, we would like to know how to exactly convert v3x to v2x addresses, because when we decode base58 and hex them, we get 36bytes. should we discard last 4 ? are those a checksum?

thanks and in advance!

Sorry, I don’t follow, there is no released compiler that has gone from supporting the new literal format to now supporting the old format?!

If you want to use literals in the style supported by compiler version 2.X (#<hex>) you use compiler version 2.X and if you want to use literals in the new style (xy_<base58check>) supported by compiler version 3.0 and forward you use compiler version 3.0?!

As for the content of the Base58Check encoded addresses, yes the last 4 bytes is a checksum - you typically check a checksum rather than discarding it though…

Also please note that I am only referring to the compiler, whatever you input into SDKs, forgae, etc is a different matter where I’m not up to speed.

2 Likes