{

How to get an ABI json file from a given contract code and address in Solidity?


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. How to get ABI json file in REMIX solidity ide editor
  • 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 find Contract ABI and copy it.

Conclusion

In summary, You learned multiple ways to get ABI json for a given contract source code or address.

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.