Definition of Application Binary Interface (ABI) of a smart contract and how to find it
The ABI of a smart contract
The Application Binary Interface (ABI) of a smart contract describes the functions available to call in the smart contract. This includes the arguments that should be sent as well as the type of value the contract is expecting. This information is stored in JSON format and provides a readable definition of the function(s) within the contract.
Let’s take a look at an example mint function in Solidity:
function mintTo(address _to, uint256 _quantity) public payable {
require(msg.value >= price, "insufficient value sent");
_mintInternal(_to, _quantity);
}
The logic is purposefully kept simple. The important part to understand is that this mint function accepts two parameters named _to and _quantity. The type that is expected precedes their name.
Now let’s look at the section of the contract ABI that describes this function:
{
"type": "function",
"name": "mintTo",
"constant": false,
"stateMutability": "payable",
"payable": true,
"inputs": [
{
"type": "uint256",
"name": "quantity"
},
{
"type": "address",
"name": "to"
}
],
"outputs": []
}
You can see that the inputs attribute of this JSON object describes the expected parameters and lists the type of value that is expected. This is important to be able to send valid transactions to the smart contract. Crossmint constructs and sends transactions to your contract, which is why we need the ABI.
How do I find my ABI?
If the contract is verified or published on the explorer
The easiest and most reliable way to find the ABI for your smart contract is to ensure your contract is published and verified on the block explorer. When this is the case we will automatically retrieve the ABI for your smart contract as soon as you input the contract address in the dev console.
If the contact is not verified or published on the explorer
Before we explain another way to find the ABI please understand verifying and publishing the contract source code is beneficial for additional reasons.
- Published source code helps instill trust in your project because anyone can examine the code themselves and understand how it works.
- It is helpful for testing and troubleshooting the project when able to interact with it directly on the block explorer.
- Finally, we’ll get the ABI automatically to help integrate with our payments tooling.
I’m a heathen and don’t want to publish the source code
It is possible to manually add the ABI to our developer console if you’re not able to publish and verify the contract source code. Part of the contract deployment process includes compiling source code to bytecode. This step also creates the JSON representation, which you can use for completing contract registration in the Crossmint Dev Console.
Where to find the ABI:
Hardat: /artifacts/contracts/[ContractName].json
Foundry: /out/[ContractName.sol]/[ContractName].json
The Crossmint Dev Console will accept the entire ABI or just the specific section related to the mint function that you’re registering. When you enter it into our dev console it should include the enclosing square brackets. Below is an example of what this looks like:
After entering the ABI correctly our interface will attempt to automatically identify the valid mint functions and fill them into the dropdown for you to select. You must double check that the correct function arguments are selected for the recipient address and NFT purchase quantity fields.
That’s all there is to it! With your contract registered you can add our payments button to your website to begin accepting credit card and cross-chain payments for your mint. You can find more information on contract registration in our documentation section here.
Then NFT checkout the steps to add the payment button here.
If you have more questions feel free to ask our support team, which is available for you 24 hours a day, 7 days of the week.