0

I want to compile a simple smart contract using truffle.

my smart contract SimpleStorage.sol

pragma solidity >=0.4.16 <0.7.0;

contract SimpleStorage {
    int public sensorData;
    constructor(int _sensorData) public {
        sensorData = _sensorData;
    }
    function setsensorData(int _sensorData) public {
        sensorData = _sensorData;
    }
    function getsensorData() view public returns (int) {
        return sensorData;
    }
}

2_deploy_contracts.js

var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
    deployer.deploy(SimpleStorage);
};

However, I could this error:

"SimpleStorage" -- Invalid number of parameters for "undefined". Got 0 expected 1!.

I have tried this, but it does not work too:

var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
    deployer.deploy(SimpleStorage, sensorData);
};

My versions:

Truffle v5.1.31 (core: 5.1.31)
Solidity v0.5.16 (solc-js)
Node v10.21.0
Web3.js v1.2.1

Could you please give a feedback?

0

Your contract requires one constructor parameter, so you have to provide that when deploying.

Your second code sample should work if the sensorData variable is of integer type. Or, better yet, of BigNumber type. So create the variable sensorData as BigNumber and pass it to the deployer just like you already do. If you're using web3.js , check out more info here: https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html#bn

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.