Created
August 6, 2018 09:45
-
-
Save domob1812/059b84288871312ce5e8ca3108515570 to your computer and use it in GitHub Desktop.
Example Python script for Xaya wallet interactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This is available in "python-jsonrpclib" on Debian/Ubuntu systems. | |
import jsonrpclib | |
import json | |
# Set according to your xaya.conf or the authentication cookie. Change port | |
# to 18396 for testnet and to 18493 for regtest. | |
user = "..." | |
password = "..." | |
wallet = "game.dat" | |
port = 8396 | |
# Connect to the JSON-RPC interface, specifying the wallet. | |
url = "http://%s:%s@localhost:%u/wallet/%s" % (user, password, port, wallet) | |
rpc = jsonrpclib.Server (url) | |
# Send coins to an address. | |
address = rpc.getnewaddress () | |
rpc.sendtoaddress (address, '42.12345678') | |
# Register a name. | |
name = "p/domob" | |
rpc.name_register (name, "{}") | |
# Wait some blocks for the transaction to be confirmed. Or on regtest net, | |
# mine a block to confirm it. | |
#rpc.generate (1) | |
# Update the name to a JSON value. Using the explicit separators option | |
# on json.dumps ensures the most compact representation (without unnecessary | |
# whitespace), which decreases transaction size and thus fees. | |
value = { | |
"g": | |
{ | |
"chess": "0-0-0", | |
"huc": | |
{ | |
"wp": [42, 42, 100, 100, 0, 0], | |
"destruct": True, | |
}, | |
}, | |
} | |
rpc.name_update (name, json.dumps (value, separators=(",", ":"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment