Installation

Installation of the Smartcontracts

Prerequirements

Smartcontracts are running inside the Docker container and uses the Hardhat framework.

Therefore, the local computer that wants to install the Smartcontracts has to be with Installed docker and docker-compose.

Once installed, the terminal should show that docker and docker-compose commands are available:

C:\Users\alp> docker version
Client: Docker Engine - Community
 Cloud integration: 1.0.12
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:14:53 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:15:47 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
C:\Users\alp> docker-compose version
docker-compose version 1.29.0, build 07737305
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

Next required Program is a Git Client. I would recommend GitKraken or Fork with a nice GUI.

Upon installation of Git, you can clone the Lighthouse Github repository into your computer:

blocklords/lighthouse-smartcontracts.git

Installation

Open in the terminal the folder of the Lighthouse Smartcontracts: Then create .env file with the following key values:

/home/lighthouse-smartcontracts/.env
MOONBEAM_DEPLOYER_ADDRESS=<wallet address>
MOONBEAM_DEPLOYER_KEY=<wallet privatekey>
MOONBEAM_REMOTE_HTTP=<RPC endpoint of the Node>

Here: MOONBEAM_DEPLOYER_ADRESS is Wallet Address of Claim verifier. MOONBEAM_DEPLOYER_KEY is the Wallet's private key that will deploy contracts on the Network. MOONBEAM_REMOTE_HTTP is the HTTPS URL of Moonbeam node.

Or a new privatekey and link to the blockchain node for other networks.

The wallet address, privatekey or remote HTTP nodes could be any wallets or node's url.

For Moonbeam and Moonriver Networks, its recommended to use https://app.onfinality.io/login rather than Official Public RPC nodes.

After installation, you can run the Docker compose to set up the Smartcontracts. The first setup will take some time, as it downloads the dependencies from the network:

C:\Users\alp\lighthouse-contracts> docker-compose up -d
Docker Compose is now in the Docker CLI, try `docker compose up`

Building lighthouse-contract
failed to get console mode for stdout: The handle is invalid.
[+] Building 1.3s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 32B                                        0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/node:14.13.1            1.3s
 => [1/7] FROM docker.io/library/node:14.13.1@sha256:2d1077c78724caf4f8bb  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 34B                                           0.0s
 => CACHED [2/7] RUN apt-get update                                        0.0s
 => CACHED [3/7] RUN apt-get install --yes build-essential inotify-tools   0.0s
 => CACHED [4/7] WORKDIR /home/node/app                                    0.0s
 => CACHED [5/7] COPY ./package.json /home/node/app/package.json           0.0s
 => CACHED [6/7] RUN npm install --save-dev "hardhat@^2.6.2"               0.0s
 => CACHED [7/7] RUN npm install                                           0.0s
 => exporting to image                                                     0.0s
 => => exporting layers                                                    0.0s
 => => writing image sha256:b2125f9b1625bf8c56e6573e7d0324971a6e34a7a5109  0.0s
 => => naming to docker.io/library/lighthouse-contracts_lighthouse-contra  0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Successfully built b2125f9b1625bf8c56e6573e7d0324971a6e34a7a5109cce7fe4a75fd3c0faf0
WARNING: Image for service lighthouse-contract was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating lighthouse-contract ... done

Commands

In order to interact with Smartcontracts, please enter into the Container:

C:\Users\alp\lighthouse-contracts> docker exec -it lighthouse-smartcontract bash
root@0c5bcd843694:/home/node/app#

This will enter into the Container. As Lighthouse smartcontracts built with Hardhat, the commands to compiling smartcontracts, deploying smartcontracts, testing or running scripts are done via Hardhat command line tool.

Here are the most common commands:

Compile

root@0c5bcd843694:/home/node/app# npx hardhat compile
Downloading compiler 0.8.0
Compiling 8 files with 0.8.0
Compilation finished successfully

npx hardhat compile compiles Solidity files. For more info about compiling at Hardhat Compiling Docs.

Deploy

root@0c5bcd843694:/home/node/app# npx hardhat run scripts/deploy-tier.js --network moonbeam
Lighthouse Tier deployed to: 0xaba7a46B9E46CdDa4B1f25e40bF691F45dA09c04

We run the scripts defined in scripts/ folder. The deployment scripts have deploy- prefix. Visit the deployment scripts and change the parameters passed to constructors. For example above command deployes LighthouseTier.sol contract.

Additionally we pass a --network argument with the network name. To change network settings or toadd another Blockchain networks (Such as Ethereum Mainnet, Ethereum Rinkeby Testnet) you can edit hardhat.config.js file inside the root folder.

For more info about deploying contracts at Hardhat Deploying Docs.

Deployment on a new network

Deploying on a new network steps:

  1. First deploy the Tier contract: npx hardhat run scripts/deploy/tier.js --network networkName Once the tier is deployed, update the scripts/addresses.js by adding a new script.

  2. Deploy the Tier Wrapper npx hardhat run scripts/deploy/tier-wrapper.js --network networkName, update the addresses.js

  3. Then deploy the scripts/deploy/project.js , then update the addesses.js

  4. Then deploy the scripts/deploy/project-wrapper, then update the addresses.js.

  5. Then deploy the registration contract. scripts/deploy/registration.js, update the addresses.js

  6. Then deploy the prefund contract. scripts/deploy/prefund.js, update the addresses.js

  7. Then deploy the auction contract. scripts/deploy/auction.js, update the addreses.js

  8. Then deploy the burn contract. scripts/deploy/burn.js, update the addresses.js

  9. Finally, deploy the burn contracts on scripts/deploy/burn-tasks.js, update the addresses.js

IMPORTANT, make sure that you check the deployment scripts, before calling them. Some of them are using the handwritten code.

Some of them are automatically detecting the network id by addresses.js. Therefore before deploying the scripts, add the network section to the addresses.js's addresses object.

The project contract and project wrapper contract asks for the kyc verifier. Use for testing purpose the address that deploys the contract

Test

root@0c5bcd843694:/home/node/app# npx hardhat test tests/1-tier.js


  Lighthouse Tier
     initiates the contracts and set the tier user to game owner. (13970ms)
     should fail to claim tier 1, before claiming tier 0 (8037ms)
     should claim tier 0 (4028ms)
     should claim tier 1 (4028ms)
     should fail to claim tier 0 after claiming tier 1
     should fail to re-claim tier 1, when tier 1 is usable by tier user (4006ms)
     uses the tier (4019ms)
     can not claim any tier except used tier, which is tier 1 (4017ms)
     re-claims tier 1 which is used (4023ms)
     should fail to claim tier 3, since tier 2 not claimed (4015ms)
     claim tier 2 (4020ms)
     claim tier 3 (4025ms)
     should fail to claim non existing tier 4
     should set fees (8035ms)
     should set claim verifier (8025ms)
     should add tier editor (8024ms)
     should delete editor (8026ms)


  17 passing (2m)

Testing contracts are done via calling npx hardhat test command by passing test script file. In Lighthouse tests are enumerated with number prefix. For example tests/1-tier.js is the LighthouseTier.sol smartcontract's Tests.

For more info about testings using Hardhat visit Hardhat Testing with ethers.js and Waffle Docs.

Last updated