Quick Start

In this guide we will deploy a simple smart contract onto Reef chain.

(Optional) Setting up a development node

To set up your local development or RPC node, check out the Reef node guide.

Alternatively, you can skip this and just use the public RPC’s (either directly) or through our Javascript and Python libraries.

New to Solidity?

Solidity is a programming language for writing DeFi applications. The Solidity programs are compiled and uploaded to Reef chain, where they run in a completely decentralized fashion.

Here are some great resources for learning Solidity:

Compiling, deploying and managing Solidity smart contracts by hand can be a chore. For this reason we have developer frameworks for Python and JS/TypeScript.

Smart Contracts on Reef vs Ethereum

The Reef chain smart contracts are written in Solidity. Any existing Ethereum smart contracts written in Solidity 0.6 or greater will work on Reef chain without a need for modifications.

However some of the tooling from Ethereum will NOT work on Reef chain due to inherent differences in the blockchain architecture.

Fortunately we have drop in replacements for most commonly used tools.

EthereumReef Chain
Metamask–>Polkadot Extension
web3–>@reef-defi/evm-provider
Truffle/Hardhat–>Reef Hardhat
Remix IDE–>Reef Remix
Etherscan–>Reefscan

Deploy your first ERC-20 Token

We are going to pick a simple ERC-20 contract for our demo, but feel free to try out other examples as well.

In this guide we are using Reef Hardhat, which is suitable for more experienced developers. If you would like to deploy your contract via an easy to use web IDE, try Reef Remix.

Clone the examples repo

git clone https://github.com/reef-defi/hardhat-reef-examples

Install the dependencies

yarn

Run the deployment script

npx hardhat run scripts/erc20/deploy.js

Interact with the ERC-20 to send tokens

We can call functions on our smart contract through the Hardhat interface:

const hre = require("hardhat");

async function main() {
  // Bob is the owner of Token contract and he wants to send some token amount to dave
  const bob = await hre.reef.getSignerByName("bob");
  const dave = await hre.reef.getSignerByName("dave");

  // Extracting user addresses
  const bobAddress = await bob.getAddress();
  const daveAddress = await dave.getAddress();

  // Token contract address
  const tokenAddress = "0x4a4fA87b810A30BE84a3a30318D6D9feEae126e5";

  // Retrieving Token contract from chain
  const token = await hre.reef.getContractAt("Token", tokenAddress, bob);

  // Let's see Dave's balance
  let daveBalance = await token.balanceOf(daveAddress);
  console.log(
    "Balance of to address before transfer:",
    await daveBalance.toString()
    );

  // Bob transfers 10000 tokens to Dave
  await token.transfer(daveAddress, 10000);

  // Let's once again check Dave's balance
  daveBalance = await token.balanceOf(daveAddress);
  console.log(
    "Balance of to address after transfer:",
    await daveBalance.toString()
  );

  // Bob's amount after transactions
  const bobBalance = await token.balanceOf(bobAddress);
  console.log(
    "Balance of from address after transfer:",
    await bobBalance.toString()
  );
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Next steps

Congratulations. You now have a running development node with the first smart contract. You and now are ready to start building your first DeFi app.

Deploy on testnet

Deploying on testnet is similar to development, however there are 2 things we need.

1.) Run a testnet node or use the public testnet RPC.

2.) Create an account and obtain testnet REEF tokens from the faucet.

To get 1000 REEF testnet tokens simply type !drip <YOUR_ADDRESS> in Reef matrix chat.

Deploy on mainnet

Deploying on mainnet is similar to development, however there are 2 things we need.

1.) Run a mainnet node or use the public mainnet RPC.

2.) Create an account and obtain Reef chain native REEF tokens from the bridge or exchange.

Verify the contract on Reefscan

Once you have deployed your smart contract on Reef Chain mainnet (or testnet), you will want to verify it on Reefscan, so that other developers can access its source code and ABI.

Verify your deployed contract on: Mainnet or Testnet

Build an UI

To start building an UI for your DApp, check the UI examples repository. It provides components as well as a single file React example, which contains most of the functionality you need to setup a DApp:

  • Polkadot.js extension connection
  • listing accounts in Polkadot.js extension
  • interacting with EVM contracts on the Reef Chain
  • generating Substrate addresses

evm-canvas-ui is a more sophisticated UI interacting with the Reef chain. It is built on top of Polkadot.js apps and uses evm-provider.js library to deploy and interact with the contracts.