Reading the ElectrumX documentation, found that the method for getting balance of any public address was: blockchain.address.get_balance
, but was removed. Now, I understand that blockchain.scripthash.get_balance
is the way for getting balances for any public address, but it requires a "scriphash".
Checking documentation for Script Hashes shows stepts for hashing the address to get script hash.
With this python code, I can get the electrum server data:
import json
from time import sleep
port = 50001
host = '127.0.0.1'
content = {
"method": "blockchain.scripthash.get_balance",
"params": ["af6df685465a42b753bf72dfdf36c43ea3c2931025411940609da6f2404b00c4"], # this is a tx_hash
"id": 0
}
def electrumx(host, port, content):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.sendall(json.dumps(content).encode('utf-8')+b'\n')
sleep(0.5)
sock.shutdown(socket.SHUT_WR)
res = ""
while True:
data = sock.recv(1024)
if (not data):
break
res += data.decode()
print(res)
sock.close()
electrumx(host, port, content)
With a transaction hash, it throws some results, not exactly the balance of any address involved:
{"id":0,"jsonrpc":"2.0","result":{"confirmed":0,"unconfirmed":0}}
My questions are:
- What means "script hash" of a public address?
- Is required to use a transaction hash, like in the code?
- Why when using tx hash always shows
"result":{"confirmed":0,"unconfirmed":0}
even if the address has funds. - Can the script hash be obtained just from a public address?
Thank you very much.