github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/demo/README.md (about) 1 # Demo 2 3 This directory contains the scripts to run fakenet (private testing network) with N local nodes, 4 primarily for benchmarking purposes. 5 6 ## Scripts 7 8 - start network: `./start.sh`; 9 - stop network: `./stop.sh`; 10 - clean data and logs: `./clean.sh`; 11 12 You can specify number of genesis validators by setting N environment variable. 13 14 ## Balance transfer example 15 16 from [`demo/`](./demo/) dir 17 18 * Start network: 19 ```sh 20 N=3 ./start.sh 21 ``` 22 23 * Attach js-console to running node0: 24 ```sh 25 go run ../cmd/u2u attach http://localhost:4000 26 ``` 27 28 * Check the balance to ensure that node0 has something to transfer (node0 js-console): 29 ```js 30 u2u.getBalance(u2u.accounts[0]); 31 ``` 32 33 output shows the balance value: 34 ```js 35 1e+27 36 ``` 37 38 * Get node1 address: 39 ```sh 40 go run ../cmd/u2u attach --exec "u2u.accounts[0]" http://localhost:4001 41 ``` 42 output shows address: 43 ```js 44 "0x02aff1d0a9ed566e644f06fcfe7efe00a3261d03" 45 ``` 46 47 * Transfer some amount from node0 to node1 address as receiver (node0 js-console): 48 ```js 49 u2u.sendTransaction( 50 {from: u2u.accounts[0], to: "0x39F2b8b6B7c772A218fB1a1c438e375047f72d88", value: "1000000000000000000"}, 51 function(err, transactionHash) { 52 if (!err) 53 console.log(transactionHash + " success"); 54 }); 55 ``` 56 output shows unique hash of the outgoing transaction: 57 ```js 58 0x68a7c1daeee7e7ab5aedf0d0dba337dbf79ce0988387cf6d63ea73b98193adfd success 59 ``` 60 61 * Check the transaction status by its unique hash (js-console): 62 ```sh 63 u2u.getTransactionReceipt("0x68a7c1daeee7e7ab5aedf0d0dba337dbf79ce0988387cf6d63ea73b98193adfd").blockNumber 64 ``` 65 output shows number of block, transaction was included in: 66 ``` 67 174 68 ``` 69 70 * As soon as transaction is included into a block you will see new balance of both node addresses: 71 ```sh 72 go run ../cmd/u2u attach --exec "u2u.getBalance(u2u.accounts[0])" http://localhost:4000 73 go run ../cmd/u2u attach --exec "u2u.getBalance(u2u.accounts[0])" http://localhost:4001 74 ``` 75 outputs: 76 ```js 77 9.99999999978999e+26 78 1.000000000000001e+27 79 ```