This repository contains a sample project that you can use as the starting point for your Theta DApp project development with the Hardhat suite.
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
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.
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))
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
npx hardhat test --network theta_privatenet
Finally, we can run the frontend with:
cd frontend
npm install
npm start
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
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.