i'm deploying a smart contract which contains several functions as well as properties. The ABI looks as follows:
[ { constant: false,
inputs: [Array],
name: 'vote',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'options',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'voters',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [],
name: 'option_amount',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: false,
inputs: [Array],
name: 'addOption',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function' },
{ inputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor' },
{ anonymous: false,
inputs: [Array],
name: 'votedEvent',
type: 'event' } ]
I just want to obtain the values of the properties and call some functions. However, i cannot find the right way. So far i tried (all lead to one error or another):
contractInstance.options.call((err, res) => console.log(err, res))
Error: Invalid number of arguments to Solidity function
contractInstance.addOption('Meeting on Saturday.')
Error: invalid address
contractInstance.methods.options().call().then(console.log)
TypeError: Cannot read property 'options' of undefined
var result = contractInstance.vote(0, {from: web3.eth.accounts[1], gas: 5500000}).call((error, result) => {
console.log(result);
});
Error: VM Exception while processing transaction: revert
I am using JavaScript and web3.js (0.20.2).
How do i create the contractInstance
?
function deployContract(compiledContract, contractName, callback){
contractABI = getContractABI(compiledContract)
newContract = web3.eth.contract(contractABI)
byteCode = compiledContract.contracts[':'+contractName].bytecode
deployedContract = newContract.new([],{
data: byteCode,
from: web3.eth.accounts[0],
gas: 4700000
}, function (e, contract){
console.log(e);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
callback(newContract, contract.address)
}
});
}
contractInstance
? You said each gives you an error. What error does each line give you?contractInstance
.