0

I'm not getting any return data from a simple function, when deployed on Sopolia testnet, it works as expected in the VM.

compiler : 0.8.7;
rpc: https://rpc-sepolia.rockx.com

function gerReferalCode() external returns ( uint256 ) {
    uint256 h;
    do {
        h = _hash(1);
    } while ( referalIsUsed[ h ] );
    referalIsUsed[ h ] = true;
    referalCode[ msg.sender ] = h;
    Data storage d = signings[ h ];
    d.owner = msg.sender;

    return h;
}

Using the same contract in remix:

remix VM (London)

input   0x8df...8c783
decoded input   {}
decoded output  {
    "0": "uint256: 3544079616"
}
logs    []

Injected Provider ( Sepolia ) :

input   0x8df...8c783
decoded output   - 
val 0 wei

Web3 code response:

blockHash
: 
"0x29810da2e36a8ec29db6e3cc50557c0ac3146283acf9231527a295dec6b0b9aa"
blockNumber
: 
2312093
contractAddress
: 
null
cumulativeGasUsed
: 
75924
effectiveGasPrice
: 
2500000007
events
: 
{}
from
: 
"0xbb4896575291881a7bbc0f945ec3bcd402a44794"
gasUsed
: 
75924
logsBloom
: 
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
status
: 
true
to
: 
"0xbc2bacef89a144acf941d2b24bfe674ede6d832e"
transactionHash
: 
"0x126f380273d8911611d2190bc67c53097d6ee012ed32f349a49786d323f7063b"
transactionIndex
: 
0
type
: 
"0x2"

1 Answer 1

0

Getting returned data from a function that potentially changes the state of the blockchain is impossible. This is one of the limitations of Solidity. That's why the function is returning the full block information.

If you want to get data, you need to change the function to a view function and not change the state in the blockchain.

Go through this if you want to try doing it with the backend.

2
  • Thank-you, you cleared up my confusion. I will emit an event instead. Commented Nov 18, 2022 at 9:56
  • Great. I am glad I could help. Commented Nov 18, 2022 at 10:15

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.