0
votes

I've just deployed a Smart Contract using the ethereum wallet. I got the Smart Contract address , I copied its ABI from remix and verified it on ethereum wallet,it was active and I could see all its methods.

Then I tried to call it from my nodejs server.I did it,I didn't get any error... But instead of a classic response like the returned values of the methods below I got mined blocks....and this is very weird I think... How am I supposed to get the methods output(the returns) ?

After that I tried to deploy another contract,this time a very simple one with the same methods name,smart contract name,parameters but without code inside the methods only a basic hard-coded return.When I deployed this contract as well I got the same mined smart contract address...which is weird,in my opinion...

I've been using 1.0.0-beta.46 , nodejs , expressjs When I said eth wallet I meant...that website generated with puppeth , on /#wallet page

Here is the basic smart contract I tried to deploy second time.The result was the same as the first smart contract.

pragma solidity >= 0.4.22 < 0.6.0;

contract BasicContract {

function function1(uint16 a,uint16 b,uint16 c,uint16 d) external payable returns(uint256){
    //a,b,c,d doesn't matter
    return 68;
}


//buy a ticket
function function2(uint128 a,uint16 b) external payable returns(uint128){
    //a,b doesn't matter
    return 94;
}

function function3(uint128 a) external payable returns(bool){
    //a doesn't matter
    return false;
}

}

1

1 Answers

0
votes

There are two ways to invoke a function in a smart contract: through a transaction sent to the network or via a local call.

Transactions don't have return values. What you get back from the library you use to make the transaction is typically the transaction hash. Any return value from the function you invoked is discarded.

A local call doesn't involve a transaction to the network and thus can't change any state. But it does give you a return value.

Which method is chosen by default for most libraries is based on whether the function is state-changing or not. If you mark your functions as view or pure, it tells the library that those functions don't change state and can then safely be just called locally to get a return value. So a simple "fix" for the above code is to make those functions pure. For functions that do change state, you'll want to switch from using return values to emitting events instead, which can be read after the transaction is mined.