Tell me, how through truffle, after the deployment of the contract, call one of its functions? I mean, during migration, how can I call the function of the contract?

var Ownable = artifacts.require("./Ownable.sol");

    module.exports = function(deployer) {
        var ownable;
        var ownableAddress;

        deployer.then(async () => {
            ownable = await deployer.deploy(Ownable);

            ownableAddress = ownable.address; 
            await ownableAddress.addContractAdresses(address);

Here is the function call

await ownableAddress.addContractAdresses(contract.address);

But I get an error

TypeError: ownableAddress.addContractAdresses is not a function

Here is the contract itself and its function

pragma solidity ^0.5.0;

contract Ownable {

    mapping (address => bool) public authorizedContractAdresses;

    function addContractAdresses(address _address) 
        authorizedContractAdresses[_address] = true;
  • I'm a little confused by the question, but generally, you call a contract method by using contract.method.call() Feb 22 '19 at 19:39

You can get a instance of deployed contract with await Ownable.deployed() after deployment. You can achieve what you are looking for with a much simpler looking script.

module.exports = async (deployer) => {
    await deployer.deploy(Ownable);
    ownableInstance = await Ownable.deployed();
    await ownableInstance.addContractAdresses(ownableInstance.address);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.