Sending a bitcoin transaction

Victor Bolum
1 min readJun 29, 2020

--

In this tutorial, we are going to look at how to send a bitcoin transaction using NBitcoin and blockcypher api.

Blockcypher api is a simple, mostly RESTful JSON API for interacting with blockchains, accessed over HTTP or HTTPS from the api.blockcypher.com domain.

Block Cypher endpoints don’t need a token for any read-only GET calls. Please register for a user token if you want to use POST and DELETE calls

This tutorial isn’t going to focus on the basics (create private key, address etc). we already talked about that here https://medium.com/@vic_tha_god/bitcoin-with-c-3f84903f6d79

Signing and building a transaction in Bitcoin can be complicated, A lot of 3rd party wallets already abstract this implementations for you. The goal here is to simplify the whole process.

Transaction Builder needs the following information :

  1. What Coins it can spend
  2. What Private Keys he knows
  3. Where does it send the money
  4. Where does it send the change
  5. Fees for the transaction

Make Payment

Get Unspent Coins

Unspent coins Outputs or UTXOs serve as globally-accessible evidence that you have bitcoin in your digital wallet. A bitcoin transaction has both an input and an output. The input is the address where the bitcoin is sent from; the output is the address where it is sent to.

Important Note : If you are interested in building a wallet, you should use NBxplorer a very simple self hostable API, that tracks only what is needed for your wallet.

the codes below is purely for demo purpose

Broadcast Transaction

--

--