Created a private chain on Geth == *By Kongphob Mangkuang* *ID:411021362* ## What we will do: * Dowload and install Geth * Create the genesis block * Start Geth * Connect to the test network * Geth commands Dowload and install Geth --- Go to the Ethereum website at [go-ethereum](https://geth.ethereum.org/downloads/ ). Select the appropriate version of geth for your operating system. Create the genesis block --- create the genesis block by navigating to the following path: ``` D:\Geth\home\eth_private_net\genesis.json. ``` Create a new file called "genesis.json", and Here's an example: ```javascript= { "config": { "chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "nonce": "0x0000000000000042", "difficulty": "0x020", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000", "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0xffffffff", "alloc": {} } ``` > *This file represents a genesis block for an Ethereum private network. It contains configuration parameters such as the chain ID, homestead block, and gas limit, as well as the initial allocation of ether to accounts in the network.* Start Geth --- Open a command prompt and type "geth" to launch the program. ``` geth ``` Connect to the test network --- Connect to the test network by running the following command: ``` geth --networkid "15" --nodiscover --datadir D:\Geth\home\eth_private_net --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi="db,eth,net,web3,txpool,personal,debug" --ws --wsaddr "localhost" --wsport "8546" --wsorigins "*" --wsapi=" db,eth,net,web3,txpool,personal,debug" --port "30303" --gcmode=archive --rpcvhosts=* --targetgaslimit "3000000" --allow-insecure-unlock --dev --dev.period 1 console 2>>D:\Geth\home\eth_private_net\geth_err.log ``` ![](https://i.imgur.com/Im5wyHQ.png) Geth commands --- Once you're connected, you can begin using Geth commands. Here are a few examples of Geth commands: ``` personal.newAccount("Password") ``` ![](https://i.imgur.com/NqlZmj0.png) > *This command is used to create a new Ethereum account with a specified password.* ``` personal.unlockAccount(eth.accounts[1]) ``` ![](https://i.imgur.com/Hui5oSy.png) > *This command is used to unlock an Ethereum account.* ``` eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(3,"ether")}) ``` ![](https://i.imgur.com/rbTU0lN.png) > *This command is used to send Ether from one account to another.* ``` web3.fromWei(eth.getBalance(eth.accounts[0]),"ether") ``` ![](https://i.imgur.com/Eq4cfIM.png) > *This command is used to retrieve the balance of an Ethereum account.* Transfer Ethereum from Geth to MetaMask. == ## What we will do: * Install MetaMask * Create a Wallet or Log In * Connect to Localhost8545 * Import Account from Geth * Click on the "Send" Button * Transaction details * Verify Transaction Install MetaMask --- Install the [MetaMask](https://metamask.io/) browser extension. Create a Wallet or Log In --- Create a new wallet on MetaMask or log in to your existing wallet by entering your seed phrase. Connect to Localhost8545 --- Open MetaMask and click on the network dropdown at the top of the screen. ![](https://i.imgur.com/uZCr444.png) Import Account from Geth --- click on the three dots at the top right corner and select "Import Account." ``` D:\Geth\home\Ethereum\keystore ``` select the keystore file. Enter the password for the account to complete the import. ![](https://i.imgur.com/oTx47aV.png) Click on the "Send" Button --- click on the "Send" button and enter the recipient's address into the search field. ![](https://i.imgur.com/VA9BEI1.png) Transaction details --- Enter the amount you want to send and review the transaction details, including the gas fee. Click "Confirm" to authorize the transfer. ![](https://i.imgur.com/miTyw1C.png) Verify Transaction --- You can verify the transaction on a "Activity" session. ![](https://i.imgur.com/94NEOhz.png) --- ###### tags: `blockchain` `geth`