Learn to use Etherscan's AI Code Reader
Non-technical people can now read Solidity smart contracts with AI
TLDR:
Etherscan Code Reader integrates ChatGPT into Etherscan so you can learn about any smart contract with the help of AI.
Code Reader is in beta so it can make mistakes, its also not free as using ChatGPT’s API costs money although its not very expensive.
Learn how to use Code Reader along with some examples of basic use-cases, such as getting an overview of a contract and learning the contract interface.
There are literally infinite prompts you can give the AI. The main limitations are around Etherscan’s own contract database.
In the past I’ve made posts on the basics of solidity code used for Ethereum smart contracts, how to navigate smart contracts on Etherscan, and even gone further and broken down smart contracts for projects like Cryptopunks and Moonbirds.
Now Etherscan has just introduced a new feature to their site that allows smart contracts to be interpreted in a human readable way by using AI! With this new feature the lay person can level up their understanding of the contracts they interact with on a day-to-day basis without even needing to understand the code itself.
While I still recommend learning the basics of Solidity so you can read a smart contract for yourself, this new integration with AI makes understanding this difficult space much easier. Today I wanted to help guide people on how to use this new feature so they can learn more about their favourite smart contracts for themselves!
Etherscan Code Reader
The Etherscan Code Reader takes smart contracts living on the Ethereum blockchain that have been uploaded to Etherscan’s huge database and integrates them with ChatGPT’s API. The beauty of this is that it reduces the need for a human to interpret the code so both technical and non-technical people can learn more about the code without actively needing to read it.
Without AI it would simply be impossible to do this as you would need technical people on Etherscan’s team to interpret each and every smart contract and write some sort of report on it. Instead you can just paste a contract address in and use the AI as a middle man to learn about what the code is doing.
On opening code reader it will first give some important warnings to consider. The key thing to remember is that its still in Beta and the AI may make mistakes that Etherescan cannot vouch for, nor could they ever reasonably check for correctness.
Also, be aware that while this is a free feature on Etherscan’s side, you will still need a ChatGPT API key which is not free to use! Nonetheless its not very expensive either.
ChatGPT API Keys
To kick things off you’ll need to generate OpenAI API keys. This is simple enough to do, as you just press the “Create New Secret Key” button and give the keys a name. Make sure to save the API key somewhere secure as they will only ever appear once.
Creating keys are easy but you may not have any credits available to use them. If this is the case you need to go to overview and “Set up a paid account”.
Note that paying for the API is separate to paying the regular monthly $20 subscription for ChatGPT Plus. With the API you are only charged for the amount you use and assuming its only Etherscan’s Code Reader it shouldn’t run up a large bill.
Using the Code Reader
With your ChatGPT API keys in hand, type the key into Etherscan’s Code Reader and add the contract address you want to look at. For this post I am using Auzki’s just released Elementals contract (0xb6a37b5d14d502c3ab0ae6f3a0e058bc9517786e) since its been grabbing a lot of the attention this week.
Once you’ve inputted the OpenAI API key and contract address you want to hit “load” and you’ll see the broken down contract if it loads successfully.
Once the smart contract has been loaded then a bar appears on the right hand side offering a prompt for you to ask the AI questions about the smart contract.
Prompting the AI
Having done the steps above you now have the full power of ChatGPT’s AI to learn about the code. You can literally ask anything you want to know, for example you can start with a simple prompt like “give a rough outline of this contract”.
As you can tell the AI does a pretty extensive job of describing everything happening in the code without us needing to read a single line of code ourselves! This is a big win even for devs who may just want a rough understanding of what a contract does.
We can go deeper than just an overview of the code by asking more specific questions. For example in the overview it mentions the function for redeeming “BeanRedeem”, so we can ask more specifically about its purpose and how the function works!
As you can see it very clearly specifies that you use a Bean to redeem the Elemental NFT and explains in detail the process by which the function does this.
Prompts on contract interface
The possibilities for what you can do are endless and if I tried to list out every different use-case I would go on forever. Yet, one very helpful use case is in interpreting the functions that can be used to interface with the contract. For example you can ask it for a list of read and write functions:
Here you can see the read functions and what data is available for you to extract.
While with the write functions you know how to save data into the contract. Understanding the interface is particularly useful if you are technical and want to create your own dApp that interfaces with the contract. For example if you have a dApp that wants to show all the NFTs in the contract you can check the exact functions you should be hooking up with to grab their metadata.
The fact you can ask for specific explanations about the interfaces means you can also figure out what “hidden abilities” the contract owner may have over the contract:
For example here you can see that the owner can change the NFT metadata with “setBaseURI” and even change the name of the contract with “setNameAndSymbol”!
Be Aware of Proxy Contracts
In Ethereum smart contract development there’s a paradigm sometimes employed where one contract is just a proxy to another contract that has the actual implementation. In these cases the AI will not be able to pull out the underlying implementation code and you’ll be wasting API calls.
Whenever you come across one of these its easy though. You just go into Etherscan and pull out the address for the code that’s being proxied by selecting “Read as Proxy”, then put that address into the Etherscan Code Reader.
As you start exploring Etherscan more you’ll also find that sometimes people upload a smart contract onto Ethereum but do not upload the matching Solidity code onto Etherscan. In these cases you cannot use the Etherscan Code Reader as Etherscan simply doesn’t have the code in its database! Either way this can also be a read flag in of itself as it suggests the developer could be trying to hide something in their code.
And that’s a wrap!
Really what I’ve shown here is just the basics to get you started. There’s all sorts of cool things that you can now do with this integration of ChatGPT within Etherscan. Its great for both coders and non-coders, since coders can get information quicker and non-coders can get an insight into the contracts they interact with.
It’s exciting to see what AI is already able to do and exciting to think what could come next. I’d say its likely one of my future posts will discuss using AI not just for non-technical people to “read” smart contracts but in fact to “write” their own too.