Skip to content

Latest commit

 

History

History
221 lines (195 loc) · 14.1 KB

README.md

File metadata and controls

221 lines (195 loc) · 14.1 KB

Randomness

Note: The following was based upon Moonbeam Truffle Box https://docs.moonbeam.network/builders/build/eth-api/dev-env/truffle/

Getting started

apt-get remove -y nodejs
rm -rf /usr/lib/node_modules/
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
npm config rm proxy
npm config rm https-proxy
  • Install Truffle dependency:
npm install -g truffle
  • Check if works
truffle --version
  • Fix permissions error since /usr/bin/truffle symlinks to below but below didn't have execute permissions for any users
chmod 755 /usr/lib/node_modules/truffle/build/cli.bundled.js
  • Setup Moonbeam Truffle Box template that this has been based upon
mkdir -p /app/dapps/evm2/randomness
DAPP_PATH=/app/dapps/evm2/randomness 
git clone https://github.com/PureStake/moonbeam-truffle-box $DAPP_PATH
cd $DAPP_PATH
```bash
* Replace template contracts with just https://github.com/hyperledger/solang/blob/main/examples/substrate/flipper.sol and add `pragma solidity ^0.8.0;`

* Update all dependencies in package.json to new major version
```bash
npm outdated
npm install -g npm-check-updates
ncu -u
npm update
  • Install dependencies
npm install
  • Install Docker in Docker container
apt-get remove docker docker-engine docker.io containerd runc
apt-get update && apt-get upgrade -y
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io -y
adduser user
usermod -aG docker user
systemctl restart docker
systemctl enable docker
apt-get install -y docker-compose-plugin
apt-get install docker-compose

Note: It is necessary to run Docker within a Docker container https://devopscube.com/run-docker-in-docker/ in order to use truffle run moonbeam ... commands from https://trufflesuite.com/boxes/moonbeam-truffle-box/, which use the Moonbeam Truffle Box plugin https://github.com/PureStake/moonbeam-truffle-plugin, which uses images from Docker hub https://hub.docker.com/r/purestake/moonbeam/tags, or setup manually by following https://docs.moonbeam.network/node-operators/networks/run-a-node/flags/, as follows:

To run a local node run similar to the following:

mkdir /opt/moonbeam
git clone https://github.com/PureStake/moonbeam /opt/moonbeam
cd /opt/moonbeam
git checkout tags/$(git describe --tags)
cargo build
./target/debug/moonbeam --help

Then configure Truffle to connect to it Moonbeam Development node_modules/.bin/truffle migrate --network dev. Note that use of Ganache does not include pre-compiles https://docs.moonbeam.network/builders/build/eth-api/dev-env/truffle/.

Preferably use Moonbase Alpha TestNet node_modules/.bin/truffle migrate --network moonbase that requires testnet tokens from the faucet https://faucet.moonbeam.network/.

Note: When running tests against Moonbase Alpha TestNet. Disconnect VPN. Try to avoid encountering errors like Too Many Requests, ProviderError, ETIMEDOUT, 32603, it is important to use a dedicated endpoint that you can get for free here https://blastapi.io/ by creating an account, creating a project, choosing Moonbase Alpha Testnet from their available endpoints and clicking "Activate", and then copying either the RPC endpoint. Note: I got error TypeError: Cannot create property 'gasLimit' on string '0x464aff' when tried using Blastapi WSS endpoint instead of RPC (https) endpoint. Note: If you change to WSS then you need to use WebsocketProvider instead of HttpProvider. Solved this error by using gasLimit in truffle-config.js (it was not necessary for HTTPS)

This is important because the public endpoint https://rpc.api.moonbase.moonbeam.network has stricter rate limiting. Ensure that you replace the public Moonbase Alpha endpoint in the truffle-config.js file with the dedicated endpoint.

Run tests

truffle test
cd /opt
wget https://github.com/PureStake/moonbeam/releases/download/v0.8.0/moonkey /opt
shasum -a 256 moonkey
  • Verify output is 019c3de832ded3fccffae950835bb455482fca92714448cc0086a7c5f3d48d3e

  • Generate account ./moonkey --w12

  • Obtain Moonbase Alpha tokens from faucet

  • Compile contracts on network of choice (i.e. "moonbase") defined in truffle.js

    • Compile full truffle compile --compile-all
  • Migrate

    • Migrate full truffle migrate --reset --compile-all --network moonbase
    • Migrate full truffle migrate --reset --compile-all --network sepolia
  • Test

    • truffle test ./test/test_MoonbaseVRF.js --verbose-rpc --network moonbase
    • truffle test ./test/test_ChainlinkVRF.js --network sepolia
  • Verify Contract - Moonbase Precompile

    • Note: To view the source code on etherscan.io, it is also necessary to Verify and Publish the source code for that too by adding your Etherscan API key to the .env file under ETHERSCAN_API_KEY
# truffle run verify Flipper --network moonbase
Verifying contracts on moonscan
   Verifying Flipper
   Pass - Verified: https://moonbase.moonscan.io/address/0x1c440D264DcCBe9b7AC84edCEC99De926Db98753#code
   Successfully verified 1 contract(s).
Verifying contracts on sourcify
   Failed to connect to Sourcify API at url https://sourcify.dev/server/chains
truffle run verify RandomNumber --network moonbase
root@ink:/app/dapps/evm2/randomness# truffle run verify RandomNumber --network moonbase
Verifying contracts on moonscan
   Verifying RandomNumber
   Pass - Verified: https://moonbase.moonscan.io/address/0x4027755C05514421fe00f4Fde0bD3F8475ce8A6b#code
   Successfully verified 1 contract(s).
Verifying contracts on sourcify
   Failed to connect to Sourcify API at url https://sourcify.dev/server/chains
  • Verify Contract - Chainlink VRF
    • Note: To view the source code on etherscan.io, it is also necessary to Verify and Publish the source code for that too by adding your Etherscan API key to the .env file under ETHERSCAN_API_KEY
# cd flipper
# truffle run verify VRFD20 --network sepolia

Verifying contracts on etherscan
   No etherscan or sepolia_etherscan API Key provided
Verifying contracts on sourcify
   Verifying VRFD20
   Pass - Verified: https://sourcify.dev/#/lookup/0xe22cdfA9d8C8e942B498696ef54584426d2f5Dd6
   Successfully verified 1 contract(s).