5

Is there a way to get the metadata(bytecode, ABI) of a deployed contract if you only know the address of the contract?

In geth there is a function in the admin interface called getContractinfo(), but I get an error when I call it: The method admin_getContractInfo does not exist/is not available

In the documentation(https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions) I saw an example but I don't think it works:

// get the contract info for contract address to do manual verification
var info = admin.getContractInfo(address) // lookup, fetch, decode
var source = info.source;
var abiDef = info.abiDefinition
2
  • What version of Geth are you using? Are you calling it from an attached console? Do any of the other admin commands work? Jul 18, 2016 at 14:41
  • 1
    Yes other admin commands work. I am using an attached console. I am using 1.4.3 version.
    – dragosb
    Jul 18, 2016 at 14:52

2 Answers 2

3

For the bytecode, you can use web3.eth.getCode(address).

For the ABI, you need to get it from whoever wrote the contract, or generate the ABI from the source code. Generally, you can't figure out the function names from the bytecode, because the bytecode only has a hash of the names, more info: Do I need a compiled contract just to get the ABI definition?


admin.getContractInfo seems to have been removed. (Note that to use getContractInfo, the earlier steps https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions#contract-info-metadata including saveInfo were also needed.)

1
  • 2
    Why was getContractInfo removed? This seems like a necessary function. How will I listen to another contract's events? There is not a "loadABI" function to do it from a file, even if the contract owner gave me the source code Sep 9, 2016 at 9:08
1

Yes, but it's a bit of a hassle (you have to reverse engineer the code/be familiar with the EVM byte code).

There is an example here with the deployed contract here.

Your Answer

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

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