Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bitcoin remote RPC client
# Remote bitcoind RPC client through SSH tunnel
# If you have a remote bitcoind you'd like to query it's RPC interface
# from, this script will help you maintain the SSH tunnel to do so.
# Set REMOTE_HOST to the user@server your remote bitcoind is running on
# Set LOCAL_FORWARD_PORT to the port you want to run the tunnel on
# Set the RPC_PASSWORD to the rpc password bitcoind is set to use.
# Install bitcoind locally, so that you can use it's query interface.
# The first run will setup the SSH tunnel, and leave it running.
# Subsequent runs will be fast.
# Check if the tunnel is already open:
port_open=$(netstat -lnt | grep$LOCAL_FORWARD_PORT | wc -l)
if [ $port_open -lt 1 ]
echo "Creating port forward..."
ssh -N $REMOTE_HOST -L $LOCAL_FORWARD_PORT:localhost:8332 &
sleep 5
# Check if the tunnel was created successfully:
port_open=$(netstat -lnt | grep$LOCAL_FORWARD_PORT | wc -l)
if [ $port_open -lt 1 ]
echo "Could not create port forward"
exit 1
bitcoind -rpcport=$LOCAL_FORWARD_PORT -rpcpassword=$RPC_PASSWORD $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment