Git Product home page Git Product logo

theta-hardhat-demo's Introduction

Theta Hardhat Demo

This repository contains a sample project that you can use as the starting point for your Theta DApp project development with the Hardhat suite.

Deployment and Testing against Theta Local Privatenet

Setup the Hardhat demo project

The first things you need to do are cloning this repository and installing its dependencies:

git clone https://github.com/thetatoken/theta-hardhat-demo
cd theta-hardhat-demo
npm install

Setup Theta local privatenet

Once installed, let's setup the Theta local privatenet with the Theta/Ethereum RPC Adaptor following this guide. The ETH RPC adaptor running at http://localhost:18888/rpc interacts with the Web3.js library by translating the Theta RPC interface into the ETH RPC interface.

Fund the test accounts with some TFuel

Execute the two commands below to fun the test accounts with some TFuel:

export SEQ=`thetacli query account --address=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab | grep sequence | grep -o '[[:digit:]]\+'`

thetacli tx send --chain="privatenet" --from=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab --to=0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A --tfuel=1000 --password=qwertyuiop --seq=$(($SEQ+1))

thetacli tx send --chain="privatenet" --from=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab --to=0x1563915e194D8CfBA1943570603F7606A3115508 --tfuel=1000 --password=qwertyuiop --seq=$(($SEQ+2))

Deploy the contract to the local privatenet

Then, on a new terminal, go to the repository's root folder and run this to deploy your contract:

npx hardhat run scripts/deploy.js --network theta_privatenet

Run the unit tests against the local privatenet

npx hardhat test --network theta_privatenet

Run the frontend

Finally, we can run the frontend with:

cd frontend
npm install
npm start

Deploy to the Theta Mainnet

First, edit the hardhat.config.js file, replace "11...1" with the actual private key of the deployer wallet (should delete the key after use, do NOT commit the private key to GitHub):

    ...
    theta_mainnet: {
      url: `https://eth-rpc-api.thetatoken.org/rpc`,
      accounts: ["1111111111111111111111111111111111111111111111111111111111111111"],
      chainId: 361,
      gasPrice: 4000000000000
    },
    ...

Next, go to the repository's root folder and run this to deploy your contract:

npx hardhat run scripts/deploy.js --network theta_mainnet

Special Notes on Testing with the Ethers.js+Waffle framework

Currently the RPC Adaptor does NOT support non-standard methods like evm_snapshot, evm_revert, and evm_mine. Thus, test cases using Fixtures (e.g. waffle.loadFixture()) are expected to fail when running against the Theta blockchain.

theta-hardhat-demo's People

Contributors

jieyilong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.