I'm new on Ethereum. I'm trying to deploy my first smart contract in my private blockchain but my function always returns 0. I wrote the simple Smart Contract:

pragma solidity^0.5.0;

contract helloNumber {
    int256 internal thisNumber;
    constructor() public {
        thisNumber = 4;

   function showNumber() external pure returns (int256) {
        return 4;  

I generated Abi and BIN with solc

 solcjs --bin helloNumber.sol
 solcjs --bin helloNumber.sol

result Bin


result ABI:


in my shell conneted to my private blockchain:

var contract = eth.contract(ABI)
var bytecode = '0xBIN'
var deploy = {from:eth.coinbase, data:bytecode, gas: 2000000}
var object= contract .new(deploy)

object.address //returns the hashcode of smart contract on private blockchain. 

object.showNumber() **//returns always 0.** 

Thanks a lot in advance for your help and sorry if it's a silly question but I'new in Ethereum. what am I doing wrong?


1 Answer 1


Your Javascript code should be asynchronous (either with async/await, or using Promise objects), because both contract.new and object.showNumber return a Promise.

For example:

async function run() {
    var contract = eth.contract(ABI);
    var bytecode = '0xBIN';
    var deploy = {from: eth.coinbase, data: bytecode, gas: 2000000};
    var object = await contract.new(deploy);
    var n = await object.showNumber();

Then you can either call run() at the end of your script, or call await run() from some other async function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.