1

When I run my code ,it told me that

“TypeError: Cannot read property 'abiDefinition' of undefined”

The error code is:

console.log(calcCompiled["info"]["abiDefinition"]);

The code that I am using is:


let source = "
pragma solidity ^0.4.0;

contract Calc { 
  uint count; 

  function add(uint a, uint b) returns(uint){ count++; return a + b; } 
  function getCount() constant returns (uint){ return count; }}

"; 

let calcCompiled = web3.eth.compile.solidity(source); console.log(calcCompiled); 
console.log("ABI definition:"); 
console.log(calcCompiled["info"]["abiDefinition"]); 

What should I do?

  • What you should do is format your post, provide more code so that we know what you are doing. – Florian Castelain Nov 18 '17 at 10:04
  • here is my code:let source = "pragma solidity ^0.4.0;contract Calc{ uint count; function add(uint a, uint b) returns(uint){ count++; return a + b; } function getCount() constant returns (uint){ return count; }}"; let calcCompiled = web3.eth.compile.solidity(source); console.log(calcCompiled); console.log("ABI definition:"); console.log(calcCompiled["info"]["abiDefinition"]); – XFL Nov 18 '17 at 13:18
  • Do you have a proper web3 object? – gisdev_p Nov 19 '17 at 8:35
1

The method eth_compileSolidity which web3.eth.compile.solidity relies on is deprecated and does not exist nor is available anymore.

An alternative is to compile using solc:

solc --abi Calc.sol -o ./build

which generates the ABI file:

├── Calc.sol
├── build
│   └── Calc.abi

Or compiling with solc in node.js:

const fs = require('fs')
const solc = require('solc')

const input = fs.readFileSync('Calc.sol')
const output = solc.compile(input.toString(), 1)
const abi = output.contracts[':Calc'].interface

console.log(abi)

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.