0

I'm working on API'S for smart contract. I'm using tronbox to compile and migrate. Error is this contract constructor expected 1 arguments, received 0 I tried to add arguments in migrations like this but it's not working.

const SimpleStorage = artifacts.require('SimpleStorage.sol');

module.exports = (deployer) => {
  const VALUE = 100;
  deployer.deploy(SimpleStorage)
    .then(() => (VALUE));
};

This is my contract.

contract SimpleStorage {
    uint256 public data;
    event UpdateData(uint256 oldValue, uint256 newValue, uint256 timestamp);
    constructor (uint256 _value) public {
        require(_value > 0, "in SimpleStorage:constructor(). Value must be greater than 0.");
        data = _value;
    }
    function updateData(uint256 _value) public {
        require(_value > 0, "in SimpleStorage:setData(). Value must be greater than 0.");
        emit UpdateData(data, _value, now);
        data = _value;
    }
    function getData() public view returns (uint256) {
        return data;
    }
} 

This is my Controller

const updatedData = async (params) => {
  try {
    const { value, contractAddress } = params;
    const contractInstance = await getContractInstance(contractAddress);
    utils.setDefaultKeyAndAddressInTronWeb(process.env.TOF_PRIVATE_KEY);
    const result = await contractInstance.methods.updateData(value).send();
    return result;
  } catch (e) {
    return {
      status: 'failure',
      message: e.message,
      data: [],
    };
  }
};
1

The format to add constructor arguments for a Truffle migration script is described here: https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#deployer-deploy-contract-args-options-

So you need to use: deployer.deploy(SimpleStorage, VALUE)

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.