4

I have the address but I want to know the name of contract. Is there any way to get that from the etherscan API?

2 Answers 2

2

There is no special API method to get the name of contract. But if you are talking about ERC20 Tokens, you can try another method [BETA]:

https://api.etherscan.io/api?module=account&action=tokentx&contractaddress=0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2&page=1&offset=5

It returns ERC20 token transfer events for a specific contract. So you can extract required information "tokenName":"Maker","tokenSymbol":"MKR" from the response.

1

getsourcecode Etherscan API endpoint returns the name of a contract. You can find the description of the endpoint here: https://etherscan.io/apis#contracts

https://api.etherscan.io/api?module=contract&action=getsourcecode&address=0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413&apikey=YourApiKeyToken

It returns `` in the resulting JSON:

{
    "status": "1",
    "message": "OK",
    "result": [{
        ...,
        "ContractName": "..."
    }]
}

It should be mentioned, that this API will return contract name only if the contract has been verified.

2
  • Doesn't work for the most contracts, e.g.` api.etherscan.io/…` vs etherscan.io/address/…
    – shredding
    Apr 10, 2022 at 14:13
  • @shredding It will work only for contracts, that have been verified on Etherscan (I updated my answer with the note at the bottom). You providing the example of the contract which has not been verified directly, but Etherscan did found verified bytecode clone. Take a look to the note on the 2nd link, you provided Note: This contract matches the deployed ByteCode of the Source Code for Contract 0x8f8ef111b67c04eb164.... If you request source code from contract 0x8f83... getsourcecode API endpoint will return contract name. Apr 20, 2022 at 15:08

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.