Giter Site home page Giter Site logo

aiobitcoin's Introduction

aiobitcoin

Python 3.6GitHub license Documentation Status GitHub issues

This is a library that provides methods for working with Bitcoin/forks daemon JSON-RPC.

Also there are tools for working with bip32 hierarchical deterministic wallets in this library . These tools were taken from three different libraries such as bitcoinlib, btclib and pycoin , because I had problems while importing keys and addresses to the Bitcoin Core when working with each of them separately.

Examples

Documentation

NOTE #0: this lib works successful with Bitcoin Core 0.17.1 , other wallet versions not tested.

NOTE #1: At the moment, not all available methods are implemented in the library , only the most common.

Donate me if you like it :)

Bitshares account -> mkbehforever007
bitcoin -> bc1qqkr72aemz59aawxf74gytrwuw4m9mj20t7e7df
ethereum -> 0xB3e5b643cFB9e2565a3456eC7c7A73491A32e31F

Supports

  • Basic methods for asynchronous work with Bitcoin/forks JSON-RPC
  • Mnemonic key generation
  • BIP32 hierarchical deterministic wallets

Installation

sudo apt install python-dev python3-dev
sudo apt install libssl-dev
pip3 install aiobitcoin

Quickstart

Simple usage:

    import asyncio
    from aiobitcoin.blockchain import Blockchain


    async def foo():
        blockchain = Blockchain(url='http://alice:[email protected]:18332')
        difficulty = await blockchain.get_difficulty()
        block_count = await blockchain.get_block_count()
        print(difficulty)
        print(block_count)
        await blockchain.close_session()

    ioloop = asyncio.get_event_loop()
    ioloop.run_until_complete(foo())

or use the same with context manager:

    import asyncio
    from aiobitcoin.blockchain import Blockchain


    async def foo():
        async with Blockchain(url='http://alice:[email protected]:18332') as blockchain:
            difficulty = await blockchain.get_difficulty()
            block_count = await blockchain.get_block_count()
            print(difficulty)
            print(block_count)


    ioloop = asyncio.get_event_loop()
    ioloop.run_until_complete(foo())

Working with bip32

All keys can be imported without problems to Bitcoin Core.

    from aiobitcoin.tools import bip32
    from aiobitcoin.tools.bip32 import MAINNET_PRV, TESTNET_PRV
    from aiobitcoin.tools.key.Key import Key
    from aiobitcoin.mnemonic import Mnemonic

    # -- Generate mnemonic phrase --
    ceed = Mnemonic().generate(encoding=False)

    # ... Output: rebel swear tomorrow burger cave giraffe ...

    # -- Generate master keys from ceed for BTC mainnet and testnet --
    testnet_mxpriv = bip32.xmprv_from_seed(ceed, TESTNET_PRV)
    # ... Output: tprv8ZgxMBicQKsPe6tqMpq6qyzFoFSr3cgh...

    mainnet_mxpriv = bip32.xmprv_from_seed(ceed, MAINNET_PRV)
    # ... Output: xprv9s21ZrQH143K4Q9MazKYy5Kuck31yFeT...

    # -- Generate master public keys from master private key --
    testnet_mxpub = bip32.xpub_from_xprv(testnet_mxpriv)
    mainnet_mxpub = bip32.xpub_from_xprv(mainnet_mxpriv)

    # ... Output: tpubD6NzVbkrYhZ4X5ghC8mzzsGuMQCxEmnh5Y...
    # ... Output: xpub661MyMwAqRbcFHVqjwnunwwY2H7JFPHdXv...

    # -- Transform master private key to WIF format and getting address of master key --
    key = Key.from_text(mainnet_mxpriv)

    wif = key.wif()
    # ... Output: L4PEssMfRgHvmpyEGxHJkFVcNWeQvZiySNMAa...

    addr = key.address()
    # ... Output: 1BGLari4SCxGXoJib27C8pAL6Ef3pFqswD

    # -- Create sub key by custom derive path --
    subkey = key.subkey_for_path('1/0/{}'.format(11))

    addr = subkey.address(use_uncompressed=False)
    wif = subkey.wif()

Roadmap

  • Add all available methods to work with Bitcoin/forks JSON-RPC
  • Rewrite to async Key tool
  • Add DASH, LTC supporting

aiobitcoin's People

Contributors

dependabot[bot] avatar mkbeh avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

djmuratb baby636

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.