Compiling a Smart Contract

Learn how to compile a Solidity smart contract, about the outputs of a Solidity compiler, and the role of ABI in Ethereum.

We’ve covered how we can use the Ethereum API to interact with an Ethereum network programmatically and have created an Infura project that we'll use instead of running our own Ethereum node. But before we can deploy our smart contract, we need to get its bytecode.

As we’ve discussed before, Ethereum clients execute bytecode, and to get the bytecode of a contract, we need to compile it. In this lesson, we'll also learn what outputs a Solidity compiler produces and how to compile a smart contract.

Compiler outputs

When we run a Solidity compiler, it produces two main types of output:

  • Bytecode: These are executable instructions that the Ethereum software understands and can execute.

  • Application binary interface (ABI): This is the machine-readable description of the interface of our smart contract.

Ethereum libraries use the ABI of a contract to identify what methods it defines, what parameters it accepts, etc. We'd need to use a smart contract’s ABI to be able to call its methods with any Ethereum library.

Using the Solidity compiler

Before we can use the Solidity compiler, we need to install it. To do this, we need to use the npm install command and install the solc package.

Get hands-on with 1200+ tech skills courses.