An application binary interface is an interface between two program modules in computer software,often, between the OS and user programs. An ABI defines how data structures and functions are accessed in machine code; this is often to not be confused with an API, which defines this access in high-level, often human-readable formats as ASCII text file. The ABI is thus the first way of encoding and decoding data into and out of machine language.
A contract’s ABI is stated as a JSON array of function descriptions and events (see Events). A function description may be a JSON object with fields type, name, inputs, outputs, constant, and payable. An occasion description object has fields type, name, inputs, and anonymous.
We use the solc command-line Solidity compiler to supply the ABI for our Faucet.sol example contract:
As we’ll see, the compiler produces a JSON array describing the 2 functions that are defined by Faucet.sol. This JSON are often employed by any application that desires to access the tap contract once it’s deployed. Using the ABI, an application like a wallet or DApp browser can construct transactions that decision the functions in Faucet with the right arguments and argument types. For instance, a wallet would know that to call the function to withdraw it might need to provide a uint256 argument named withdraw amount. The wallet could prompt the user to supply that value, then create a transaction that encodes it and executes the withdraw function.
All that’s needed for an application to interact with a contract is an ABI and therefore the address where the contract has been deployed.
Selecting a Solidity Compiler and Language Version
As we saw within the previous code, our Faucet contract compiles successfully with Solidity version 0.6.4. But what if we had used a special version of the Solidity compiler? The language remains in constant flux and things may change in unexpected ways. Our contract is fairly simple, but what if our program used a feature that was only added in Solidity version 0.6.1 and that we tried to compile it with 0.6.0?
To resolve such issues, Solidity offers a compiler directive referred to as a version pragma that instructs the compiler that the program expects a selected compiler (and language) version. Let’s check out an example:
Let’s add a pragma directive to our Faucet contract. We’ll name the new file Faucet2.sol, to stay track of our changes as we proceed through these examples starting in Faucet2.sol: Adding the version pragma to Faucet.
Example 2. Faucet2.sol: Adding the version pragma to Faucet link:code/Solidity/Faucet2.sol