Writing the contract

Let's begin writing the orderbook smart contract with the functions that we discussed in the previous section:

  1. Start by creating a smart contract file called Orderbook.sol.
  2. We begin by defining first the Solidity compiler version:
pragma solidity ^0.5.2;
  1. Next, we import the open-zeppelin contract template (ERC20.sol):
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

Importing the ERC20 contract allows our smart contract to transfer the Gold and USD ERC20 tokens to and from the trader's Ethereum accounts, using the Transfer method in the ERC20 contract.

  1. Next, we define the contract name as Orderbook:
contract Orderbook {using SafeMath for uint;

We also use the using keyword to declare that we'll be ...

Get Blockchain Development for Finance Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.