Skip to content

Commit 01428c6

Browse files
author
Cris Perez
committed
Add an example to push raw transaction to the network via RPC
1 parent 57ef95f commit 01428c6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

examples/push_tx.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from bitcoinrpc.authproxy import AuthServiceProxy
2+
3+
#################################################
4+
# Sending a transation to the network with RPC #
5+
#################################################
6+
7+
# ---------------------------------------------------------------------------------------------------------------------
8+
# The following piece of code serves as an example of how to send a transaction created with any of the pieces of
9+
# code of the other examples to the P2P network. The code assumes you have access to a Bitcoin node with RPC
10+
# enabled. RPC authentication details have to be provided in the proper variables.
11+
#
12+
# Alternatively, you can also push the transaction to the network with a 3rd party service.
13+
#
14+
# Note that this code has an additional dependency: bitcoinrpc
15+
# This dependency is not required by bitcoin_tools, since it is only used in this example, and most users
16+
# will not need to use it.
17+
# ---------------------------------------------------------------------------------------------------------------------
18+
19+
20+
# Set RPC configuration
21+
rpc_user = "" # set roc user
22+
rpc_password = "" # set rpc password
23+
rpc_server = "" # set rpc server
24+
rpc_port = 18332
25+
26+
# Test connection
27+
rpc_connection = AuthServiceProxy("http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port))
28+
get_info = rpc_connection.getinfo()
29+
print get_info
30+
31+
# Send transaction
32+
# raw_transaction = ...
33+
# rpc_connection.sendrawtransaction(raw_transaction)

0 commit comments

Comments
 (0)