Skip to content

Commit

Permalink
Add an example to push raw transaction to the network via RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Cris Perez committed Mar 9, 2018
1 parent 57ef95f commit 01428c6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/push_tx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from bitcoinrpc.authproxy import AuthServiceProxy

#################################################
# Sending a transation to the network with RPC #
#################################################

# ---------------------------------------------------------------------------------------------------------------------
# The following piece of code serves as an example of how to send a transaction created with any of the pieces of
# code of the other examples to the P2P network. The code assumes you have access to a Bitcoin node with RPC
# enabled. RPC authentication details have to be provided in the proper variables.
#
# Alternatively, you can also push the transaction to the network with a 3rd party service.
#
# Note that this code has an additional dependency: bitcoinrpc
# This dependency is not required by bitcoin_tools, since it is only used in this example, and most users
# will not need to use it.
# ---------------------------------------------------------------------------------------------------------------------


# Set RPC configuration
rpc_user = "" # set roc user
rpc_password = "" # set rpc password
rpc_server = "" # set rpc server
rpc_port = 18332

# Test connection
rpc_connection = AuthServiceProxy("http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port))
get_info = rpc_connection.getinfo()
print get_info

# Send transaction
# raw_transaction = ...
# rpc_connection.sendrawtransaction(raw_transaction)

0 comments on commit 01428c6

Please sign in to comment.