Setup the ETH RPC Adaptor for Local Privatenet

The theta-eth-rpc-adaptor project is aiming to provide an adaptor which translates the Theta RPC interface to the Ethereum RPC interface. Please find the currently supported Ethereum RPC APIs here.

Setup Theta Local Privatenet with ETH RPC Adaptor

This section will show you how to download precompiled binaries and launch a Theta local privatenet with the ETH RPC adaptor. If you want to compile the RPC adaptor from source code, please check out the steps here.

On Linux

First, run the following commands in a terminal (or screen/tmux session) to download and unzip the Theta local privatenet binaries and configs:

wget https://theta-downloader.s3.amazonaws.com/ethrpc/theta_local_privatenet_linux.tar.gz
tar -xvzf theta_local_privatenet_linux.tar.gz
cd theta_local_privatenet_linux/bin

Next, execute the following command to start the Theta local privatenet:

./theta start --config=../privatenet/validator --password=qwertyuiop

In a second terminal (or screen/tmux session), under the same theta_local_privatenet_linux/bin directory, execute the following command to start the Theta ETH RPC Adaptor:

./theta-eth-rpc-adaptor start --config=../privatenet/eth_rpc_adaptor

After the adaptor creates 10 test wallets, in a third terminal (or screen/tmux session), run the following curl command to verify that the Theta local privatenet and Adaptor work properly:

curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}' http://127.0.0.1:18888/rpc

The response should be {"jsonrpc":"2.0","id":67,"result":"0x16e"}. Next, checkout how to config Truffle and/or Hardhat to run tests against the Theta local privatenet here.

On macos

First, run the following commands in a terminal to download and unzip the Theta local privatenet binaries and configs.

wget https://theta-downloader.s3.amazonaws.com/ethrpc/theta_local_privatenet_macos.tar.gz
tar -xvzf theta_local_privatenet_macos.tar.gz
cd theta_local_privatenet_macos/bin

Starting with macOS v10.15 Catalina, only signed applications are allowed to run. We need to run the following commands to manually add the downloaded binaries to the allowed applications. You might be prompted to enter your Macbook password or use the touch ID to allow access.

sudo spctl --add ./theta
sudo spctl --add ./thetacli
sudo spctl --add ./theta-eth-rpc-adaptor

Now, execute the following command to start the Theta local privatenet:

./theta start --config=../privatenet/validator --password=qwertyuiop

In a second terminal, under the same theta_local_privatenet_macos/bin directory, execute the following command to start the Theta ETH RPC Adaptor:

./theta-eth-rpc-adaptor start --config=../privatenet/eth_rpc_adaptor

After the adaptor creates 10 test wallets, in the third terminal, run the following curl command to verify that the Theta local privatenet and Adaptor work properly:

curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}' http://127.0.0.1:18888/rpc

The response should be {"jsonrpc":"2.0","id":67,"result":"0x16e"}. Next, checkout how to config Truffle and/or Hardhat to run tests against the Theta local privatenet here.

Note: If you are using a Mac with the M1 chip, you might need to add the arch -arch x86_64 prefix to the commands as shown below:

# In the first terminal
arch -arch x86_64 ./theta start --config=../privatenet/validator --password=qwertyuiop

# In the second terminal
arch -arch x86_64 ./theta-eth-rpc-adaptor start --config=../privatenet/eth_rpc_adaptor

Configure Truffle/Hardhat for local testing

The genesis snapshot of the Theta local privatenet contains prefunded test wallets, which can be used to run unit test cases with Truffle/Hardhat. In particular, the following test wallets each has a starting balance of 500,000,000 TFuel, which should be sufficient to run many tests:

Test Wallet Private Key                                              Test Wallet Address                            Initial TFuel Balance
1111111111111111111111111111111111111111111111111111111111111111     0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A     50000000000000000000000000 wei
2222222222222222222222222222222222222222222222222222222222222222     0x1563915e194D8CfBA1943570603F7606A3115508     50000000000000000000000000 wei
3333333333333333333333333333333333333333333333333333333333333333     0x5CbDd86a2FA8Dc4bDdd8a8f69dBa48572EeC07FB     50000000000000000000000000 wei
4444444444444444444444444444444444444444444444444444444444444444     0x7564105E977516C53bE337314c7E53838967bDaC     50000000000000000000000000 wei
5555555555555555555555555555555555555555555555555555555555555555     0xe1fAE9b4fAB2F5726677ECfA912d96b0B683e6a9     50000000000000000000000000 wei
6666666666666666666666666666666666666666666666666666666666666666     0xdb2430B4e9AC14be6554d3942822BE74811A1AF9     50000000000000000000000000 wei
7777777777777777777777777777777777777777777777777777777777777777     0xAe72A48c1a36bd18Af168541c53037965d26e4A8     50000000000000000000000000 wei
8888888888888888888888888888888888888888888888888888888888888888     0x62f94E9AC9349BCCC61Bfe66ddAdE6292702EcB6     50000000000000000000000000 wei
9999999999999999999999999999999999999999999999999999999999999999     0x0D8e461687b7D06f86EC348E0c270b0F279855F0     50000000000000000000000000 wei
1000000000000000000000000000000000000000000000000000000000000000     0x7B2419E0Ee0BD034F7Bf24874C12512AcAC6e21C     50000000000000000000000000 wei

Truffle Configs

To use these prefunded test wallets for Truffle, modidfy the truffle-config.js file to include the following. Then, you can run the test cases with truffle test --network theta_privatenet.

const HDWalletProvider = require('@truffle/hdwallet-provider');

...

module.exports = {
  mocha: {
    enableTimeouts: false,
    before_timeout: 1000000000
  },
  networks: {
    theta_privatenet: {
      provider: () => {
        var privateKeyTest01 = '1111111111111111111111111111111111111111111111111111111111111111'; 
        var privateKeyTest02 = '2222222222222222222222222222222222222222222222222222222222222222';
        var privateKeyTest03 = '3333333333333333333333333333333333333333333333333333333333333333';
        var privateKeyTest04 = '4444444444444444444444444444444444444444444444444444444444444444';
        var privateKeyTest05 = '5555555555555555555555555555555555555555555555555555555555555555';
        var privateKeyTest06 = '6666666666666666666666666666666666666666666666666666666666666666';
        var privateKeyTest07 = '7777777777777777777777777777777777777777777777777777777777777777';
        var privateKeyTest08 = '8888888888888888888888888888888888888888888888888888888888888888';
        var privateKeyTest09 = '9999999999999999999999999999999999999999999999999999999999999999';
        var privateKeyTest10 = '1000000000000000000000000000000000000000000000000000000000000000';
 
        return new HDWalletProvider({
          privateKeys: [privateKeyTest01, privateKeyTest02, privateKeyTest03, privateKeyTest04, privateKeyTest05, privateKeyTest06, privateKeyTest07, privateKeyTest08, privateKeyTest09, privateKeyTest10],
          providerOrUrl: 'http://localhost:18888/rpc',
        });
      },
      network_id: 366,
      gasPrice: 4000000000000,
    },
    ...
 },
 ...
}

Hardhat Configs

To use these prefunded test wallets for Hardhat, modidfy the hardhat.config.js file to include the following. Then, you can run the test cases with npx hardhat test --network theta_privatenet .

module.exports = {
  mocha: {
    timeout: 1000000000,
  },
  networks: {
    theta_privatenet: {
      url: "http://localhost:18888/rpc",
      accounts: [
        "1111111111111111111111111111111111111111111111111111111111111111", // 0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A
        "2222222222222222222222222222222222222222222222222222222222222222", // 0x1563915e194D8CfBA1943570603F7606A3115508
        "3333333333333333333333333333333333333333333333333333333333333333", // 0x5CbDd86a2FA8Dc4bDdd8a8f69dBa48572EeC07FB
        "4444444444444444444444444444444444444444444444444444444444444444", // 0x7564105E977516C53bE337314c7E53838967bDaC
        "5555555555555555555555555555555555555555555555555555555555555555", // 0xe1fAE9b4fAB2F5726677ECfA912d96b0B683e6a9
        "6666666666666666666666666666666666666666666666666666666666666666", // 0xdb2430B4e9AC14be6554d3942822BE74811A1AF9
        "7777777777777777777777777777777777777777777777777777777777777777", // 0xAe72A48c1a36bd18Af168541c53037965d26e4A8
        "8888888888888888888888888888888888888888888888888888888888888888", // 0x62f94E9AC9349BCCC61Bfe66ddAdE6292702EcB6
        "9999999999999999999999999999999999999999999999999999999999999999", // 0x0D8e461687b7D06f86EC348E0c270b0F279855F0
        "1000000000000000000000000000000000000000000000000000000000000000", // 0x7B2419E0Ee0BD034F7Bf24874C12512AcAC6e21C
      ],
      chainId: 366,
      gasPrice: 4000000000000,
    },
    ...
 },
 ...
}

In addition to these prefunded test wallets, the RPC adaptor will create 10 random test wallets the first time it runs, which will be useful for running tests with dev tools like Truffle and Hardhat. After the test wallets are created, the ETH RPC APIs will be ready for use. To fund these randomly generated test wallets, you can execute the following command (replace <WALLET_ADDRESS> with the actual address):

export SEQ=`./thetacli query account --address=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab | grep sequence | grep -o '[[:digit:]]\+'`
./thetacli tx send --chain="privatenet" --from=0x2E833968E5bB786Ae419c4d13189fB081Cc43bab --to=<WALLET_ADDRASS> --tfuel=10000 --password=qwertyuiop --seq=$(($SEQ+1))

What’s Next
Did this page help you?