I want to build something similar to the Read Contract tab feature of etherscan which reads a contract and return all the public props like: - name, totalSupply, decimals, etc.
However I have not found any information on web3 documentation.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI want to build something similar to the Read Contract tab feature of etherscan which reads a contract and return all the public props like: - name, totalSupply, decimals, etc.
However I have not found any information on web3 documentation.
Etherscan is only able to provide that for contracts that verify their source code, or for contracts that follow a specification, such as ERC20.
This is because reading a contract (or writing it) requires that you know the ABI for that contract. If you have the source code, you can generate it. If you don't have the code, but the contract follows a known spec, you can use the ABI for that spec (note that any additional methods implemented outside the spec will not be accessible in that case).
If you have the ABI, it's simply a matter of calling specific functions on the contract. Web3 contract interactions are covered in the documentation here.
myContract.myProp
or myContract.myProp.call()
like if I wanna get the tokenSupply prop: myContract.tokenSuply
?
Aug 1, 2018 at 12:27