This tutorial shows ways to generate an Application Binary Interface json file for a given contract source code.
Application Binary Interface is an interface that contains functions and arguments of a contract in JSON format. It is used to encode and decode data to and from blockchain transactions.
Generate ABI json file using local solc compiler
If the solidity compiler is installed local machine and solc command is working, then type the below command to get the Abi file. To install the solc compiler,
- First, you need to have nodejs installed,
- Next install solc package which is a javascript binding for solidity.
- Once the npm library is done, the
solc
command works
solc contract.sol --abi
you can --abi
option to the command line to get generated ABI code.
This generates an ABI json file.
Also, the --bin
option is provided to deploy the contract.
How to get the ABI file in Remix IDE
The following are steps to get an ABI JSON file for a given smart contract.
- Go to
https://remix.ethereum.org/
and create a contract source code - Go to the Solidity Compiler tab and select ABI from the top-bottom tab as the given screenshot.
- you can click on ABI and copy it to the clipboard
[
{
"inputs": [],
"name": "addEmployee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
How to get an ABI json file for a given contract address?
Another way is to get abi json file for a given contract address.
- go to EtherScan
- Enter the contract address to open the contract
- Go to the Contract tab and Select
Code
- Inside
Code
, you can findContract ABI
and copy it.
Conclusion
In summary, You learned multiple ways to get ABI json for a given contract source code or address.