Coder Social home page Coder Social logo

bitcoinlib's Introduction

BitcoinLib

Bitcoin Elixir

Want to interact with the Bitcoin network through a DIY app? Look no further, this library is about doing it with Elixir in a very abstract way. It keeps the cryptography jargon to a minimum, while sticking to the Bitcoin glossary.

The easiest way to start is to try the wallet operations livebook.

Donations

This library is being built in the wild according to these principles

  • Free to use
  • Developer friendly
  • Modular

Arguably, the most important part is that it is unbiased.

If you want to keep it that way, and want to promote its active development, please send donations here: bc1qs0hd8wws09jm68fg4ymnsdvxdjggsg3jg09xh4

donations QR code

That address, along with the private key that goes with it have both been created using the current lib. The same will apply for very transaction created to spend said funds.

Thank you!

How to use

First, make sure you've got elixir set up and that you know the language's basics.

Then, create a project and add the dependency in mix.exs.

def deps do
  [
    {:bitcoinlib, "~> 0.4.7"}
  ]
end

Finally, head to the private key creation documentation to get started.

Useful links

Here are the most useful links

Technicalities

This lib can

  • Generate entropy with dice rolls
  • Create private keys
  • Derive public keys from private keys
  • Handle Hierarchical Deterministic (HD) Wallets, including
    • Seed Phrases
    • Derivation Paths
  • Serialize/Deserialize Private Keys (xprv, yprv, zprv)
  • Serialize/Deserialize Public Keys (xpub, ypub, zpub)
  • Generate Addresses
  • Sign P2PKH transactions

Mid term goals

  • Sign Transactions (PSBT)
  • Taproot support

Supported address types

Address Type Description Starts With Supported
P2PKH Pay to Primary Key Hash 1
P2WPKH-nested-in-P2SH Nested Segwit 3
P2WPKH Native Segwit bc1q
P2TR Taproot bc1p Eventually...

Referenced bips

A bip is a Bitcoin Improvement Proposal. Here is a list of those that are at least partially implemented in this library:

  • bip13 - Address Format for pay-to-script-hash
  • bip16 - Pay to Script Hash
  • bip32 - Hierarchical Deterministic Wallets
  • bip39 - Mnemonic code for generating deterministic keys
  • bip44 - Multi-Account Hierarchy for Deterministic Wallets
  • bip49 - Derivation scheme for P2WPKH-nested-in-P2SH based accounts
  • bip84 - Derivation scheme for P2WPKH based accounts
  • bip141 - Segregated Witness (Consensus layer)
  • bip144 - Segregated Witness (Peer Services)
  • bip173 - Base32 address format for native v0-16 witness outputs
  • bip174 - Partially Signed Bitcoin Transaction Format

PSBT bips, in the process of being implemented

Running static analysis

$ mix deps.get
$ mix test
$ mix dialyzer

bitcoinlib's People

Contributors

codlco avatar roosoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitcoinlib's Issues

Segwit transaction failure

Tried to follow this livebook for Segwit transactions (P2SH), had to fix some APIs due to outdated dependency. I was able to generate an encoded transaction like below for address 2MzhhVCh8GvuXyzbc7wJae9WbYyCH9CUytY on testnet. Tried to spend the received funds in this txn.

01000000016a99b7047272e1bf5fc4b3b0f54b3313ce2e55d3d78b883fd907be15a6feaaa3000000006a473044022040c814d00da3b95aeccca8958370299e34bd4ca2fce03ff1f228c9045c01356f02201e252dc1dab37a1b735920f938042a70929ce080dc9867422b36fc9a77c0a2a40121039d109ebbb5ea0b46b993b182198209822748680696b471d1e606ef0f1e0935e5ffffffff02f40100000000000017a91409d6cbc4a478c8f1cbde9085b10fb84519591afb87881300000000000017a914e8046c97f9c1c38ff6c15e4d7696385309d543888700000000

Got an error of
mandatory-script-verify-flag-failed (Opcode missing or not understood) when broadcasting it on the chain.

@RooSoft Can you kindly remind what might be the issue here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.