S
S
Sergey2017-12-06 03:16:27
JavaScript
Sergey, 2017-12-06 03:16:27

How can I get the value of a variable based on smart contract abi (Etherium VM) and web3.js?

I am using web3.js and trying to get the value of a variable from a smart contract.
My code for this is:
var contract = web3.eth.contract(abi).at(address);
where abi is a json array and address is the actual normal and working address where the smart contract is located.
The abi json part of the object is here:

{
"constant": true,
"inputs": [],
"name": "weiRaised",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false ,
"type": "function"
},

When I use this code: I see "weiRaised" in the browser console. But if I use I see 'undefined'. What am I doing wrong? How can I get the value of a variable based on smart contract abi and web3.js? There is nothing on the official Stack Exchange on the topic.
console.log(contract.abi[0].abi[6].name);
console.log(contract.abi[0].abi[6].inputs);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh, 2017-12-06
well @AnneSmith

I didn’t deal with ether in any way, but here’s what the console returns using simple examples

var inp = [];
undefined
inp[0]
undefined
var inp = [0]
undefined
inp[0]
0
var inp = [99]
undefined
inp[0]
99

that is, if your inputs contains an empty array without data, then you cannot get data from it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question