I'm trying to deploy the following smart contract:
pragma solidity ^0.5.00;
contract TestContract {
address public owner;
string public word;
constructor(string memory _word) public{
owner = msg.sender;
word = _word;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function getWord() public view returns (string memory) {
return(word);
}
function updateWord(string memory _word) public onlyOwner {
word = _word;
}
}
But I'm having trouble deploying it with the constructors parameters. I'm using MetaMask and web3.js (that I got from here: https://github.com/ethereum/web3.js/blob/develop/dist/web3.js) with the following test code:
var Web3 = require('web3');
var web3 = new Web3(web3.currentProvider);
var code = '0x608060405234801561001057600080fd5b506040516106b...';
var abi = JSON.parse('[{"constant":true,"inputs":[],"name":"word","outputs":...');
var myContract;
function createExampleContract() {
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('code').innerText = code;
web3.eth.defaultAccount = web3.eth.coinbase;
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if(err) {
console.error(err);
return;
} else if(contract.address){
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
}
function callExampleContract() {
var param = parseInt(document.getElementById('value').value);
myContract.getWord(param, function(err, result) {
if (err) {
console.log('e: ' + err);
} else {
console.log('r: ' + result);
}
});
}
I got the code
and abi
with this two terminal commands solc --bin contract.sol
and solc --abi contract.sol
I was trying arguments:['param']
after data:code
and the contract deployment goes through but when I call the getWord
method, this error shows up BigNumber Error: new BigNumber() not a base 16 number
and searching on-line I found out that this may accour due to null
values returning from the method call. So how do I deploy the contract with constructor arguments properly?
Thank you all!! =)