You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2.4 KiB

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

    • Install manually by downloading and installing the Bitcoin Core software from GitHub. You can copy and paste the following text in your shell and execute.

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.
$ 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
$ 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:
$ bitcoin-cli -regtest generatetoaddress 101 <your address>
...
$
  • Send a transaction of 2 bitcoins to the second address.
$ bitcoin-cli -regtest sendtoaddress <the second address> 2
...
$
  • List the last transactions
$ 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! Below an example on how you should export your variable.
exports.txid = ...

Congrats for your first Bitcoin transaction!

Notions