|
| 1 | +# Example RPC CLI |
| 2 | + |
| 3 | +### Simple Regtest Test |
| 4 | + |
| 5 | +1. Start local regtest bitcoind. |
| 6 | + ``` |
| 7 | + mkdir -p /tmp/regtest/bitcoind |
| 8 | + bitcoind -regtest -server -fallbackfee=0.0002 -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> -datadir=/tmp/regtest/bitcoind -daemon |
| 9 | + ``` |
| 10 | +2. Create a test bitcoind wallet and set bitcoind env. |
| 11 | + ``` |
| 12 | + bitcoin-cli -datadir=/tmp/regtest/bitcoind -regtest -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> -named createwallet wallet_name="test" |
| 13 | + export RPC_URL=127.0.0.1:18443 |
| 14 | + export RPC_USER=<your-rpc-username> |
| 15 | + export RPC_PASS=<your-rpc-password> |
| 16 | + ``` |
| 17 | +3. Get test bitcoind wallet info. |
| 18 | + ``` |
| 19 | + bitcoin-cli -rpcwallet="test" -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> -datadir=/tmp/regtest/bitcoind -regtest getwalletinfo |
| 20 | + ``` |
| 21 | +4. Get new test bitcoind wallet address. |
| 22 | + ``` |
| 23 | + BITCOIND_ADDRESS=$(bitcoin-cli -rpcwallet="test" -datadir=/tmp/regtest/bitcoind -regtest -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> getnewaddress) |
| 24 | + echo $BITCOIND_ADDRESS |
| 25 | + ``` |
| 26 | +5. Generate 101 blocks with reward to test bitcoind wallet address. |
| 27 | + ``` |
| 28 | + bitcoin-cli -datadir=/tmp/regtest/bitcoind -regtest -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> generatetoaddress 101 $BITCOIND_ADDRESS |
| 29 | + ``` |
| 30 | +6. Verify test bitcoind wallet balance. |
| 31 | + ``` |
| 32 | + bitcoin-cli -rpcwallet="test" -datadir=/tmp/regtest/bitcoind -regtest -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> getbalances |
| 33 | + ``` |
| 34 | +7. Set descriptor env and get address from RPC CLI wallet. |
| 35 | + ``` |
| 36 | + export DESCRIPTOR="wpkh(tprv8ZgxMBicQKsPfK9BTf82oQkHhawtZv19CorqQKPFeaHDMA4dXYX6eWsJGNJ7VTQXWmoHdrfjCYuDijcRmNFwSKcVhswzqs4fugE8turndGc/1/*)" |
| 37 | + cargo run -- --network regtest address next |
| 38 | + ``` |
| 39 | +8. Send 5 test bitcoin to RPC CLI wallet. |
| 40 | + ``` |
| 41 | + bitcoin-cli -rpcwallet="test" -datadir=/tmp/regtest/bitcoind -regtest -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> sendtoaddress <address> 5 |
| 42 | + ``` |
| 43 | +9. Sync blockchain with RPC CLI wallet. |
| 44 | + ``` |
| 45 | + cargo run -- --network regtest sync |
| 46 | + <CNTRL-C to stop syncing> |
| 47 | + ``` |
| 48 | +10. Get RPC CLI wallet unconfirmed balances. |
| 49 | + ``` |
| 50 | + cargo run -- --network regtest balance |
| 51 | + ``` |
| 52 | +11. Generate 1 block with reward to test bitcoind wallet address. |
| 53 | + ``` |
| 54 | + bitcoin-cli -datadir=/tmp/regtest/bitcoind -rpcuser=<your-rpc-username> -rpcpassword=<your-rpc-password> -regtest generatetoaddress 10 $BITCOIND_ADDRESS |
| 55 | + ``` |
| 56 | +12. Sync the blockchain with RPC CLI wallet. |
| 57 | + ``` |
| 58 | + cargo run -- --network regtest sync |
| 59 | + <CNTRL-C to stop syncing> |
| 60 | + ``` |
| 61 | +13. Get RPC CLI wallet confirmed balances. |
| 62 | + ``` |
| 63 | + cargo run -- --network regtest balance |
| 64 | + ``` |
| 65 | +14. Get RPC CLI wallet transactions. |
| 66 | + ``` |
| 67 | + cargo run -- --network regtest txout list |
| 68 | + ``` |
0 commit comments