I am trying to duplicate some of the function of web3.js in C++. I don't really know much javaScript. I can see how the code calls into simple RPC calls such as eth_getBlockByNumber or eth_getTransactionByHash. That's easy enough.

I can't figure out how web3.js calls one of the functions on a smart contract though. For example, how does it call a function like an ERC20 token getTotalSupply?

I'm not looking for Javascript code explain how to use the capability, but instead the code that implements the functionality.

1 Answer 1


To call a function on contract web3 has to first instantiate the contract and that capability is implemented at https://github.com/ethereum/web3.js/blob/develop/lib/web3/contract.js#L262-L274

Then we can send requests to the contract and that capability is implemented at https://github.com/ethereum/web3.js/blob/develop/lib/web3/function.js


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.