mirror of https://github.com/01-edu/public.git
nprimo
2 years ago
committed by
Niccolò Primo
1 changed files with 52 additions and 18 deletions
@ -1,38 +1,72 @@
|
||||
# Send Transaction |
||||
## send-transaction |
||||
|
||||
The purpose of this exercise is to create a simple Bitcoin transaction locally using the command line. As we use new tools this exercise is guided. |
||||
|
||||
### Instructions |
||||
|
||||
- Install a Bitcoin node. There are two solutions : |
||||
|
||||
- Use a preconfigured image for a virtual machine such as [cryptotux](https://cryptotux.org/) |
||||
- Install manually by downloading and installing the Bitcoin Core software from [github](https://github.com/bitcoin/bitcoin/releases). |
||||
- Launch Bitcoin core daemon on _regtest_ network. You can do so with `bitcoind -regtest -fallbackfee=0.00000003` assuming the executable is in your shell's path. |
||||
- Install manually by downloading and installing the Bitcoin Core software from [GitHub](https://github.com/bitcoin/bitcoin/releases). |
||||
|
||||
```console |
||||
export bitcoinCoreVersion="24.0.1" |
||||
wget -q "https://bitcoincore.org/bin/bitcoin-core-$bitcoinCoreVersion/bitcoin-$bitcoinCoreVersion-x86_64-linux-gnu.tar.gz" |
||||
tar xzf "bitcoin-$bitcoinCoreVersion-x86_64-linux-gnu.tar.gz" |
||||
sudo mv bitcoin-$bitcoinCoreVersion/bin/* /usr/local/bin |
||||
rm -rf bitcoin-$bitcoinCoreVersion/ |
||||
rm "bitcoin-$bitcoinCoreVersion-x86_64-linux-gnu.tar.gz" |
||||
``` |
||||
|
||||
- Launch Bitcoin core daemon on _regtest_ network. You can do so with the following command assuming the executable is in your shell's path. |
||||
|
||||
```console |
||||
$ bitcoind -chain=regtest -daemon -fallbackfee=0.00000003 |
||||
$ |
||||
``` |
||||
|
||||
- Create manually a wallet and two addresses on _Bitcoin regtest_. You may do this by running the following commands |
||||
```bash |
||||
bitcoin-cli createwallet "testwallet" |
||||
bitcoin-cli getnewaddress |
||||
bitcoin-cli getnewaddress |
||||
``` |
||||
- Generate 101 blocks to get fresh bitcoins. You need 101 blocks as the Bitcoin you receive from mining are locked for 100 blocks. |
||||
You may use the following command `bitcoin-cli -regtest generatetoaddress 101 <your address>` |
||||
|
||||
```console |
||||
$ bitcoin-cli -regtest createwallet "testwallet" |
||||
... |
||||
$ bitcoin-cli -regtest getnewaddress |
||||
... |
||||
$ bitcoin-cli -regtest getnewaddress |
||||
... |
||||
$ |
||||
``` |
||||
|
||||
- Generate 101 blocks to get fresh bitcoins. You need 101 blocks as the Bitcoin you receive from mining are locked for 100 blocks. You may use the following command: |
||||
|
||||
```console |
||||
$ bitcoin-cli -regtest generatetoaddress 101 <your address> |
||||
... |
||||
$ |
||||
``` |
||||
|
||||
- Send a transaction of 2 bitcoins to the second address. |
||||
|
||||
- List the last transactions `bitcoin-cli listtransactions` |
||||
- Create a js file and exports the hash of your transaction in a variable `txid`. |
||||
```console |
||||
$ bitcoin-cli -regtest sendtoaddress <the second address> 2 |
||||
... |
||||
$ |
||||
``` |
||||
|
||||
### Usage |
||||
- List the last transactions |
||||
|
||||
```js |
||||
exports.txid = |
||||
"be3d0d245e7dce50964ac9157aee7e18a3828e11d89f72ee0bc3f76b526e5bb"; |
||||
```console |
||||
$ bitcoin-cli -regtest listtransactions |
||||
... |
||||
$ |
||||
``` |
||||
|
||||
- Create a JS file `send-transaction.js` with a variable `txid` that will store the hash of your transaction. The variable `txid` needs to be importable from an external file! |
||||
|
||||
Congrats for your first Bitcoin transaction! |
||||
|
||||
### Notions |
||||
|
||||
- A linux image with developer tools [cryptotux.org](https://cryptotux.org/) |
||||
- Bitcoin core node [bitcoin.org](https://bitcoin.org/) |
||||
- Send to address [reference](https://wbnns.github.io/bitcoin-dev-docs/reference/rpc/sendtoaddress.html) |
||||
- [Bitcoin for developers introduction](https://wbnns.github.io/bitcoin-dev-docs/examples/intro.html) |
||||
- A Linux image with developer tools [cryptotux.org](https://cryptotux.org/) |
||||
|
Loading…
Reference in new issue