Inspect Your Contract's ABI

Noah Hein
InstructorNoah Hein
Share this video with your friends

Social Share Links

Send Tweet

You will learn how to inspect the Application Binary Interface — commonly referred to as ABI — of your smart contract. ABI's are generated whenever your contract is complied. It is the source of truth for how the contract expects information flowing into it to be shaped. You need the ABI to take a look at how to send transactions to and from a smart contract.

forge book reference

Instructor: [0:01] To interact with our newly deployed smart contract, we will use another tool that we installed from Foundry, which is Cast. In order to use Cast, we need to know the shape of the contract that we are going to be interacting with. We need to get what's called the ABI from our smart contract. [0:21] An ABI stands for Application Binary Interface. In the same way that you interact with APIs, an ABI is the same idea, but for a smart contract instead of a particular programming interface.

[0:36] To get the ABI for our smart contract, we use Forge. Forge has an inspect tool that lets you get various information for any particular contract. We can use forge inspect Number. It knows to look in source and then go through the contracts to find the particular contract that you have.

[0:56] We will forge inspect Number. Then it takes another argument. In our case, we want the ABI.

[1:04] There's many different options that you can pass here. You can look in the Forge book to find an exhaustive reference list of all of the different options that forge inspect has.

[1:15] You can see here it spits out a big blob. This is essentially our contract in a program. You can see here it's a big JSON blob. It has a list of inputs. You can see here that we have the name _num as uint256. Here you can see the type that it is. In this case, this is our constructor that we're looking at in this particular input right here.

[1:43] This gives us all of the information that we need to actually start sending transactions to and from our local chain.