Skip to content

Commit d9180c5

Browse files
committed
Merge #20145: contrib: add getcoins.py script to get coins from (signet) faucet
e9c8e6e doc: add contrib/signet readme (Karl-Johan Alm) 355d0c4 contrib: add getcoins.py script to get coins from (signet) faucet (Karl-Johan Alm) Pull request description: This adds a small python script that can be used to fetch Signet coins from the default (or custom) faucet. ACKs for top commit: laanwj: Code and documentation review ACK e9c8e6e Tree-SHA512: 9aaeb96bf0c636a38e2dbe4cfc8b3ef907b1c05d0b782ee51223014952e07ce45a071c7e99aa9aa7700196a67f8a47d74d13e5e8d6890b9be503acd2bacd4d4f
2 parents 1cc5e69 + e9c8e6e commit d9180c5

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

contrib/signet/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Contents
2+
========
3+
This directory contains tools related to Signet, both for running a Signet yourself and for using one.
4+
5+
getcoins.py
6+
===========
7+
8+
A script to call a faucet to get Signet coins.
9+
10+
Syntax: `getcoins.py [-h|--help] [-c|--cmd=<bitcoin-cli path>] [-f|--faucet=<faucet URL>] [-a|--addr=<signet bech32 address>] [-p|--password=<faucet password>] [--] [<bitcoin-cli args>]`
11+
12+
* `--cmd` lets you customize the bitcoin-cli path. By default it will look for it in the PATH
13+
* `--faucet` lets you specify which faucet to use; the faucet is assumed to be compatible with https://github.com/kallewoof/bitcoin-faucet
14+
* `--addr` lets you specify a Signet address; by default, the address must be a bech32 address. This and `--cmd` above complement each other (i.e. you do not need `bitcoin-cli` if you use `--addr`)
15+
* `--password` lets you specify a faucet password; this is handy if you are in a classroom and set up your own faucet for your students; (above faucet does not limit by IP when password is enabled)
16+
17+
If using the default network, invoking the script with no arguments should be sufficient under normal
18+
circumstances, but if multiple people are behind the same IP address, the faucet will by default only
19+
accept one claim per day. See `--password` above.

contrib/signet/getcoins.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
import argparse
7+
import subprocess
8+
import requests
9+
import sys
10+
11+
parser = argparse.ArgumentParser(description='Script to get coins from a faucet.', epilog='You may need to start with double-dash (--) when providing bitcoin-cli arguments.')
12+
parser.add_argument('-c', '--cmd', dest='cmd', default='bitcoin-cli', help='bitcoin-cli command to use')
13+
parser.add_argument('-f', '--faucet', dest='faucet', default='https://signetfaucet.com/claim', help='URL of the faucet')
14+
parser.add_argument('-a', '--addr', dest='addr', default='', help='Bitcoin address to which the faucet should send')
15+
parser.add_argument('-p', '--password', dest='password', default='', help='Faucet password, if any')
16+
parser.add_argument('bitcoin_cli_args', nargs='*', help='Arguments to pass on to bitcoin-cli (default: -signet)')
17+
18+
args = parser.parse_args()
19+
20+
if args.addr == '':
21+
if args.bitcoin_cli_args == []:
22+
args.bitcoin_cli_args = ['-signet']
23+
# get address for receiving coins
24+
try:
25+
args.addr = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getnewaddress', 'faucet', 'bech32']).strip()
26+
except FileNotFoundError:
27+
print('The binary', args.cmd, 'could not be found.')
28+
exit()
29+
30+
data = {'address': args.addr, 'password': args.password}
31+
try:
32+
res = requests.post(args.faucet, data=data)
33+
except:
34+
print('Unexpected error when contacting faucet:', sys.exc_info()[0])
35+
exit()
36+
print(res.text)

0 commit comments

Comments
 (0)