Cannot pass addresses to init function

The contract I am developing has an init function with signature:

public stateful function init( white: address, black: address)

Now i’m trying to execute a test script through forgae tests where the contract is deployed passing explicit addresses to the function as:

const deployPromise = compiledContract.deploy( ["ak_tWZrf8ehmY7CyB1JAoBmWJEeThwWnDpU4NadUdzxVSbzDgKjP", "ak_FHZrEbRmanKUe9ECPXVNTLLpRP2SeQCLCT6Vnvs9JuVu78J7V"], options);

This does not work, with the following error:

AssertionError: Could not deploy the Reversi Smart Contract: expected promise to be fulfilled but it was rejected with ‘Error: Http request for https://compiler.aepps.com/encode-calldata failed with status code 403. Status: Forbidden. \nError data: {“reason”:“Type errors\nUnbound variable ak_tWZrf8ehmY7CyB1JAoBmWJEeThwWnDpU4NadUdzxVSbzDgKjP at line 221, column 28\n\nUnbound variable ak_FHZrEbRmanKUe9ECPXVNTLLpRP2SeQCLCT6Vnvs9JuVu78J7V at line 221, column 81\n”}’

Any help? Thanks in advance.

1 Like

I think this topic is explained here: [Solved] How to properly encode callData using address as argument?

1 Like

So it’s a problem of the compiler encoder not interpreting ak_ addresses as call arguments ? I’m using forgae 1.4.0.

I know nothing about Forgae I am afraid… But the nice address literals are only available in version 3.0.0 of the compiler.

I guess I’m using 2.x series, I wonder how I can use compiler version 3.0 from forgae.

Hey @hernandp you can update forgae to latest version - 1.4.1 and you can try this both ways for calling your functions

First, using the forgae deployer in the tests you can do something like this:

const Deployer = require('forgae').Deployer;

let deployer = new Deployer(network, privateKey)
let initParams = ["ak_zPoY7cSHy2wBKFsdWJGXM7LnSjVt6cn1TWBDdRBUMC7Tur2NQ", "ak_zPoY7cSHy2wBKFsdWJGXM7LnSjVt6cn1TWBDdRBUMC7Tur2NQ"]

let result = await deployer.deploy("./contracts/ExampleContract.aes", initParams)

So, in the first line, you are requiring the forgae deployer in your tests file and then you can use it like described. You can also view the example deploy.js script for reference.

Second, if you don’t want to use forgae’s deployer but the SDK instead:

const config = {
host: "http://localhost:3001/",
internalHost: "http://localhost:3001/internal/",
gas: 200000,
ttl: 55,
compilerUrl: 'https://compiler.aepps.com'
}

  owner = await Ae({
        url: config.host,
        internalUrl: config.internalHost,
        keypair: ownerKeyPair,
        nativeMode: true,
        networkId: 'ae_devnet',
        compilerUrl: config.compilerUrl
    });

let contractSource = utils.readFileRelative('./contracts/ExampleContract.aes', "utf-8"); // Read the aes file
    let initParams = ["ak_zPoY7cSHy2wBKFsdWJGXM7LnSjVt6cn1TWBDdRBUMC7Tur2NQ", "ak_zPoY7cSHy2wBKFsdWJGXM7LnSjVt6cn1TWBDdRBUMC7Tur2NQ"]
    let contractObject = await owner.getContractInstance(contractSource);
    const deployPromise = await contractObject.deploy(initParams, options);

All of this is explained and described in the tests file in forgae.

Please test with latest forgae version - 1.4.1, it should work.

Best,
Martin

2 Likes