From 0a6ccd1ef5975cf2d0bc5909137defb879f7d4ee Mon Sep 17 00:00:00 2001 From: Shannon Appelcline Date: Tue, 20 Jun 2017 12:30:33 -0700 Subject: [PATCH] Update 12_3_Programming_Bitcoind_with_C.md --- 12_3_Programming_Bitcoind_with_C.md | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/12_3_Programming_Bitcoind_with_C.md b/12_3_Programming_Bitcoind_with_C.md index 8f4d2ca..4517358 100644 --- a/12_3_Programming_Bitcoind_with_C.md +++ b/12_3_Programming_Bitcoind_with_C.md @@ -25,3 +25,41 @@ Since this is our first functional C program, we're going to try and keep it sim 3. Combine multiple UTXOs if necessary If you want to continue to expand this example, these would be an excellent place to start, especially the latter points, which will approve your understanding and usage of actual RPC commands. + +## Write Your Transaction Software + +We're now going to take that plan step by step + +### 1. Request an Address and an Amount + +Inputting the information is easy enough via command line arguments: +``` +if (argc != 3) { + + printf("ERROR: Only %i arguments! Correct usage is '%s [recipient] [amount]'\n",argc-1,argv[0]); + exit(-1); + +} + +char *tx_recipient = argv[1]; +float tx_amount = atof(argv[2]); + +printf("Sending %4.8f BTC to %s\n",tx_amount,tx_recipient); +``` + +> **WARNING:** A real program would need much better sanitization of these variables. + +### 2. Set an Arbitrary Fee + +We're just setting the 0.0005 BTC fee that we've reguarly used to ensure that our test transactions go through quickly: +``` +float tx_fee = 0.0005; +float tx_total = tx_amount + tx_fee; +``` + +> **WARNING:** A real program would calculate a fee that minimized cost while ensuring the speed was sufficient for the sender. + +### X. Prepare Your RPC + +### 3. Find a UTXO +