A step by step guide to setting up blockchain testnet using local network. This example is presented on macOS.
- Install MyCrypto https://download.mycrypto.com/ (macOS may need to adjust permissions to open apps from unidentified developers: >> System Preferences >> Security & Privacy). Note: DO NOT SHARE YOUR PRIVATE KEY with anyone, under any circumstances. We are creating a testnet in this example and creating tokens with no value, but this should always be the practice.
- Install Go Ethereum Tools https://geth.ethereum.org/downloads/. Be sure to download the latest stable release bundle for your operating system. Decompress archive into local repo where you plan to run your nodes. For this example, we will be using a repo called 'Block_Party'.
Open terminal / git bash and navigate to newly created Block_Party repo. Proceed with the following commands:
- Create directory for 1st node within the Block_Party repo ./geth account new --datadir n1
After entering this line of code, you will be prompted to provide a password. Once provided, you will see a public address for the new key as well as the filepath to the secret key file in the terminal. Be sure to save all of this information as it will be needed later.
-
Create directory for 2nd node ./geth account new --datadir n2
-
Initialize Puppeth blockchain service management tool: ./puppeth
-
You will be prompted to specify a network name. In this example, we will use 'fiesta'
-
In the prompt that follows, first select option '2' to configure a new genesis, then '1' to create a new genesis from scratch and then '2' to select 'Proof-of-Authority' consensus engine. DEFAULT options for how long block should take
-
When prompted, paste both wallet addresses one at a time into the list of accounts to seal. (note: first 2 alphanumerics '0x' provided)
-
Paste the wallet addresses again in the list of accounts to pre-fund. There are no block rewards in PoA, so you'll need to pre-fund. Choose 'no' when prompted to pre-fund with wei as it keeps genesis cleaner
-
Specify network/chain ID as '42069'
-
Complete the rest of the prompts, and when you are back at the main menu, choose the "Manage existing genesis" option.
-
Export genesis configurations. This will fail to create two of the files, but you only need party.json file. You can delete the party-harmony.json file from the repo.
Your code should look like this:
-
Use the control + c command on keyboard to exit from puppeth
-
Initialize each node with the new party.json with geth. ./geth --datadir n1 init fiesta.json ./geth --datadir n2 init fiesta.json
-
Run the first node, unlock the account, enable mining, and the RPC flag. Only one node needs RPC enabled. ./geth --datadir node1 --unlock "SEALER_ONE_ADDRESS" --mine --rpc --allow-insecure-unlock ** Be sure to copy down the enode address as it will be needed in the next step. This address appears after 'Starting P2P Networking' appears in Terminal
-
Open a new terminal and navigate to Block_Party repo. Start second node ./geth --datadir node2 --unlock "SEALER_TWO_ADDRESS" --mine --port 30304 --bootnodes "enode://SEALER_ONE_ENODE_ADDRESS@127.0.0.1:30303" --ipcdisable --allow-insecure-unlock
NOTE: Type your password and hit enter - even if you can't see it visually! Your private PoA blockchain should now be running!
With both nodes up and running, the blockchain can be added to MyCrypto for testing.
- Open the MyCrypto app, then click Change Network at the bottom left:
-
Click "Add Custom Node", then add the custom network information that you set in the genesis.
-
Make sure that you scroll down to choose Custom in the "Network" column to reveal more options like Chain ID. You will need to select the custom network that was just created and input the chain ID '42069'. Use ETH as currency and local host network: http://127.0.0.1:8545 (This points to the default RPC port on your local machine). Once all fields have been addressed, click [Save & Use Custom Node]
After connecting to the custom network in MyCrypto, it can be tested by sending money between accounts.
-
Select the View & Send option from the left menu pane, then click Keystore file.
-
On the next screen, click Select Wallet File, then navigate to the keystore directory inside your Node1 directory, select the file located there, provide your password when prompted and then click Unlock.
This will open your account wallet inside MyCrypto.
- Looks like we're filthy rich! Before you quit your day job, recall that this is the balance that was pre-funded for this account in the genesis configuration; these millions of ETH tokens are just for testing purposes. Back to the salt mines...
- In the To Address box, type the account address from Node2, then fill in an arbitrary amount of ETH:
- Confirm the transaction by clicking "Send Transaction", and the "Send" button in the pop-up window.
- Click the Check TX Status when the green message pops up, confirm the logout:
You should see the transaction go from Pending to Successful in around the same blocktime you set in the genesis.
You can click the Check TX Status button to update the status