Write the Smart Contract
We’ll start our Dapp by writing the smart contract that acts as the back-end logic and storage.
    1.
    Create a new file named Adoption.sol in the contracts/ directory.
    2.
    Copy the following code:
1
pragma solidity ^0.5.0;contract Adoption {
2
address[16] public adopters; // Adopting a pet
3
function adopt(uint petId) public returns (uint) {
4
// check that petId is in range of our adopters array
5
require(petId >= 0 && petId <= 15); // add the address who called this function to our adopter array
6
adopters[petId] = msg.sender; // return the petId provided as a confirmation
7
return petId;
8
} // Retrieving the adopters
9
function getAdopters() public view returns (address[16] memory) {
10
return adopters;
11
}
12
}
Copied!
Note: Code from Truffle’s Pet-Shop tutorial — if you want to look deeper into the Solidity code, they slowly go through the Truffle link explaining the details.

Compiling

Solidity is a compiled language, meaning we need to compile our Solidity to bytecode for the Ethereum Virtual Machine (EVM) to execute. Think of it as translating our human-readable Solidity into something the EVM understands.
TomoChain is EVM-compatible, which means that every contract written in Ethereum can be seamlessly ported to TomoChain without effort
In a terminal, make sure you are in the root of the directory that contains the Dapp and type:
1
truffle compile
Copied!
You should see output similar to the following:
1
Compiling ./contracts/Migrations.sol...
2
Compiling ./contracts/Adoption.sol...
3
Writing artifacts to ./build/contracts
Copied!
Last modified 1yr ago
Copy link
Contents
Compiling