github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/getting-started/local-setup/premining-balances.md (about) 1 --- 2 id: premining-balances 3 --- 4 5 # Premining Balances 6 7 ## Overview 8 9 In this tutorial, you will gain an understanding on how to premine native currency on a local Gno.land chain. 10 Additionally, you will understand how to query the account balance after you premine it. 11 12 Premining balance is the process of making sure some accounts (addresses) have specific funds when the chain initially 13 launches. In the context of local chain deployments, premine balances are used to ensure the user accounts (developers) 14 have ample funds to interact with the chain and facilitate contract deployments. 15 16 ## Prerequisites 17 18 - **`gnoland` and `gnokey` set up. Reference the [Installation](local-setup.md#3-installing-other-gno-tools) guide 19 for steps** 20 21 ## 1. Clean chain data 22 23 In order for us to premine funds on a fresh chain, we need to make sure we do not have any leftover blockchain data 24 from previous chain runs. 25 26 The blockchain node, when it runs, works with an embedded DB locally on disk to store execution data (such as 27 configuration files, or the state DB). For Gno blockchain nodes, this working directory is labeled as `gnoland-data` by 28 default. 29 30 To clean out old blockchain data, navigate to the `gno.land` folder and run the appropriate make command: 31 32 ```bash 33 cd gno.land 34 make fclean 35 ``` 36 37 ## 2. Change the `genesis_balances.txt` file 38 39 When the Gno node boots up, among other things, it reads a file called `genesis_balances.txt` to generate the initial 40 balance set for the blockchain. 41 42 An example of how this looks like in the initial `genesis.json` file after the chain starts: 43 44 ```bash 45 "app_state": { 46 "@type": "/gno.GenesisState", 47 "balances": [ 48 "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5=10000000000000ugnot", 49 "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj=10000000000000ugnot", 50 "g1f4v282mwyhu29afke4vq5r2xzcm6z3ftnugcnv=1000000000000ugnot", 51 "g127jydsh6cms3lrtdenydxsckh23a8d6emqcvfa=1000000000000ugnot" 52 ], 53 ``` 54 55 The `genesis_balances.txt` file is located at `./gno.land/genesis/genesis_balances.txt`. 56 57 To add a new entry to the premine table, simply append a line to the end of the file: 58 59 ```bash 60 g1qpymzwx4l4cy6cerdyajp9ksvjsf20rk5y9rtt=10000000000ugnot # My address 61 ``` 62 63 Replace `g1qpymzwx4l4cy6cerdyajp9ksvjsf20rk5y9rtt` with the address you want balance on, and `10000000000ugnot` with the 64 desired `ugnot` balance. 65 66 ## 3. Start the local chain 67 68 Now that our address and the desired premine balance are located in the `genesis_balances.txt` file, we can start the 69 local Gno node. 70 71 To run the local Gno node, make sure you are in the `gno.land` sub-folder, and run the appropriate make command: 72 73 ```bash 74 cd gno.land 75 gnoland start 76 ``` 77 78 This command will initialize the Gno node, generate the `genesis.json` with our newly added premine information, and 79 start the chain. 80 81  82 83 ## 3. Check the account balance 84 85 To check the balance of any account (or the account we just premined), we can use the following ABCI query: 86 87 ```bash 88 gnokey query --remote localhost:26657 bank/balances/g1qpymzwx4l4cy6cerdyajp9ksvjsf20rk5y9rtt 89 ``` 90 91 Let's break down this command: 92 93 - **`--remote`** - the JSON-RPC URL of the running Gno node. In the case of a local deployment, the default value 94 is `localhost:26657` 95 - **`bank/balances/g1qpymzwx4l4cy6cerdyajp9ksvjsf20rk5y9rtt`** - the ABCI query targets the `bank` module to find 96 the `balances` for address `g1qpymzwx4l4cy6cerdyajp9ksvjsf20rk5y9rtt`. Replace the address with your desired address 97 98  99 100 ## Conclusion 101 102 That's it 🎉 103 104 You have successfully premined a native currency balance on a locally-running Gno chain! 105 Additionally, you have also learned how to query the native currency balance for an address, using built-in ABCI queries 106 and the `gnokey` tool.