Kekeの日記

エンジニア、読書なんでも

Start your Bitcoin app with just 4 lines of code. go-btcrpc

Hey Guys. A great announcement to everyone who wants to use blockchain.

I made a simple bitcoin library to interact with your bitcoin node called go-btcrpc.

What's JSONRPC?

JSONRPC is like JSON but the object is a bit different. Unlike JSON, JSONRPC has a mandatory key like jsonrpc or method.

And all methods of the Http requests are POST. It is used for remote method executing.

In the blockchain application, the infrastructure looks like this. The app server interacts to the blockchain though the bitcoin node server. You can get the docker file of the bitcoin node amacneil/bitcoin.

https://qiita-image-store.s3.amazonaws.com/0/153320/744a8c95-5e4e-73f4-9d4a-5e6d5e0cfcc5.png

How can I create a app?

For my example, I use a golang webframework for my application server. And I use this go-btcrpc package for the interaction between these two.

image.png

How to use this package?

This is extremely easy.

package main

import (
  "fmt"
  btcrpc "github.com/KeisukeYamashita/go-btcrpc"
  )

func main() {
    basicAuth := &BasicAuth{
        Username: os.Getenv("USERNAME"),
        Password: os.Getenv("PASSWORD"),
    }
    c := NewRPCClient(os.Getenv("BTCD_ENDPOINT"), basicAuth)
    address := "my88QLpf2RYYDdNMmDwYvfx6TFc6NXaELa"
    balance := c.GetBalance(address)
    fmt.Print(balance) // 0.13514 BTC
}

That's all. It alreadly got the balance(the mount of bitcoin) of the address. There is more useful methods, see the README.md for more specific infomations about the methods. Not all methods of bitcoin api is implemented!

How to get the bitcoin node?

See the official repo for installation. bitcoin/bitcoin

Remember to set the basic auth option when you start your bitcoind.

How to contribute?

Just send a pull request to this repo. I believe that this project is very cool lets people develop blockchain application much easlier.

Make world a better place. That's why this project is OSS.

Questions

Please feel free to ask questions about this package via email, github, facebook and such like. I've created app on Ethereum,Bitcoin, Ripple, Lisk...etc.

Any questions are welcomed.

Email: 19yamashita15@gmail.com

Github: @KeisukeYamashita