Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#Fullnode - Scripting Bitcoin with Python #14

Open
ghost opened this issue Feb 16, 2016 · 2 comments
Open

#Fullnode - Scripting Bitcoin with Python #14

ghost opened this issue Feb 16, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 16, 2016

Getting Started - Bitcoin Fullnode and Python Programming

OK so you have your #fullnode but now what? You want to be able to program with it of course.

You can use the Bitcoin RPC directly however it can be a bit slow on the Rasberry Pi 2 (http://bitcoinupdates.net/bitcoin-cli-very-slow-to-respond-to-rpc-calls-raspberry-pi/)
but with some additional libraries interfacing with bitcoin becomes faster and quite simple.

Step 1

Assuming you have complied and installed bitcoin, use the following commands to download and install the latest python-bitcoinlib from Peter Todds repository on Github

git clone https://github.com/petertodd/python-bitcoinlib

Then run the following commands as root to install

cd python-bitcoinlib
python setup.py build
python setup.py install

Congratulatons, you are now able to interface with the bitcoin RPC at higher speed, using the simple commands from this python library.

Here are two very basic example scripts you are able to run on your #fullnode

balance.py

import bitcoin
#bitcoin.SelectParams("testnet")

import bitcoin.rpc
myproxy = bitcoin.rpc.Proxy()

bal = myproxy.getbalance()

print "Your balance is ...", bal, " satoshis."
print "Thank you for using bitcoin, have a nice day!"

exit()

send.py

import bitcoin
#bitcoin.SelectParams("testnet")

import bitcoin.rpc
import bitcoin.wallet

myproxy = bitcoin.rpc.Proxy()
bal = myproxy.getbalance()

print ("Your balance is ...")
print (bal)

address = raw_input("Please enter the address to send to: ")
if len(address) == 0 :
    print ("No address supplied, have a nice day!")
else :
    satoshis = raw_input("Please enter the number of satoshis to send: ")
    if len(satoshis) == 0 :
        print("We can not send zero satoshis, please enter only numbers, have a nice day!")
    else :
        myproxy.sendtoaddress(address, satoshis)
        print("Coins have been sent!")
exit()
@ralphtheninja
Copy link

This is great! We should script this as well and also put the example code inside this repository. That way when we clone and install the fullnode, everything is there for the user.

@ghost
Copy link
Author

ghost commented Feb 28, 2016

More example scripts can be found in https://github.com/OpenProvenance/python-bitcoinlib-scripting so if we could script the installation of the python-bitcoinlibs then the repo could also be cloned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant