-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_new_key.py
More file actions
42 lines (35 loc) · 1.86 KB
/
Copy path00_new_key.py
File metadata and controls
42 lines (35 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# SPDX-License-Identifier: MIT
"""00 - Make a fresh testnet receiving address with your own node's wallet.
Testnet only. Never run this against a wallet that holds real coins.
This asks your node for a brand-new address and shows the public key behind it.
Fund the address from cypherfaucet.com, watch it arrive with recipe 02, and spend
it with recipe 08 (the node-wallet path). The JavaScript recipe 00 does the same
thing offline, without a node.
RPC_USER=... RPC_PASS=... python 00_new_key.py
"""
import requests
from config import RPC_URL, RPC_USER, RPC_PASS
def rpc(method, params=None):
payload = {"jsonrpc": "1.0", "id": "ex", "method": method, "params": params or []}
try:
r = requests.post(RPC_URL, json=payload, auth=(RPC_USER, RPC_PASS), timeout=15)
except requests.exceptions.RequestException:
raise SystemExit(f"could not reach your node at {RPC_URL}. is it running with RPC "
"enabled? see testnethub.com/run-node")
if r.status_code == 401:
raise SystemExit("the node rejected the login: set RPC_USER / RPC_PASS (see testnethub.com/rpc-safety)")
body = r.json()
if body.get("error"):
raise SystemExit(f"the node rejected the call: {body['error']['message']}")
return body["result"]
address = rpc("getnewaddress", ["", "bech32"]) # native SegWit (tb1.../ tltc1...)
pubkey = rpc("getaddressinfo", [address])["pubkey"]
print(f"address : {address}")
print(f"pubkey : {pubkey}")
print("fund it : https://cypherfaucet.com")
# 02 reads the explorer, so point TESTNET_NET at the same coin as your node.
print(f"watch : python 02_address.py {address}")
print("spend : python 08_build_and_send.py <destination-address> <amount-in-coins>")
print()
print("The node holds this key for you. If you want a standalone WIF instead,")
print("the JavaScript recipe 00 prints one directly (offline, no node).")