htdf sdk
Project description
HTDF sdk
the sdk of HTDF
require python3.6+
Install
pip3 install htdfsdk --upgrade
Example
Create address
from htdfsdk import Address, HtdfPrivateKey
privkey = HtdfPrivateKey('')
print(privkey.private_key)
print(privkey.address)
# privkey2 = HtdfPrivateKey(privkey.private_key)
# pk3 = HtdfPrivateKey('279bdcd8dccec91f9e079894da33d6888c0f9ef466c0b200921a1bf1ea7d86e8')
# addr3 = Address('htdf1xwpsq6yqx0zy6grygy7s395e2646wggufqndml')
Normal HTDF Transaction
from pprint import pprint
from htdfsdk import HtdfRPC, HtdfTxBuilder, htdf_to_satoshi, Address, HtdfPrivateKey
def test_htdf_normal_transfer():
htdfrpc = HtdfRPC(chaid_id='testchain', rpc_host='192.168.0.171', rpc_port=1317)
from_addr = Address('htdf1xwpsq6yqx0zy6grygy7s395e2646wggufqndml')
to_addr = Address('htdf1jrh6kxrcr0fd8gfgdwna8yyr9tkt99ggmz9ja2')
private_key = HtdfPrivateKey('279bdcd8dccec91f9e079894da33d6888c0f9ef466c0b200921a1bf1ea7d86e8')
from_acc = htdfrpc.get_account_info(address=from_addr.address)
signed_tx = HtdfTxBuilder(
from_address=from_addr,
to_address=to_addr,
amount_satoshi=htdf_to_satoshi(20.1215),
sequence=from_acc.sequence,
account_number=from_acc.account_number,
chain_id=htdfrpc.chain_id,
gas_price=100,
gas_wanted=30000,
data='',
memo='htdfsdk test'
).build_and_sign(private_key=private_key)
tx_hash = htdfrpc.broadcast_tx(tx_hex=signed_tx)
print('tx_hash: {}'.format(tx_hash))
# mempool = htdfrpc.get_mempool_trasactions()
# pprint(mempool)
# memtx = htdfrpc.get_mempool_transaction(transaction_hash=tx_hash)
# pprint(memtx)
tx = htdfrpc.get_tranaction_until_timeout(transaction_hash=tx_hash)
pprint(tx)
# tx = htdfrpc.get_transaction(transaction_hash=tx_hash)
# pprint(tx)
Contract Transaction
import json
from pprint import pprint
from htdfsdk import Address, HtdfRPC, HtdfPrivateKey, HtdfTxBuilder, htdf_to_satoshi
from htdfsdk import HtdfContract
from htdfsdk import to_checksum_address, remove_0x_prefix
def test_hrc20_name():
with open('./AJC_sol_AJCToken.abi', 'r') as abifile:
# abi = abifile.readlines()
abijson = abifile.read()
# print(abijson)
abi = json.loads(abijson)
contract_address = Address('htdf1k78exwfuta66m3sxgfjd6zuw8m7zykfmas0nrf')
htdfrpc = HtdfRPC(chaid_id='testchain', rpc_host='192.168.0.171', rpc_port=1317)
hc = HtdfContract(rpc=htdfrpc, address=contract_address, abi=abi)
name =hc.call( hc.functions.name() )
print(name)
assert name == "AJC chain"
pass
def test_hrc20_totalSupply():
with open('./AJC_sol_AJCToken.abi', 'r') as abifile:
# abi = abifile.readlines()
abijson = abifile.read()
# print(abijson)
abi = json.loads(abijson)
contract_address = Address('htdf1k78exwfuta66m3sxgfjd6zuw8m7zykfmas0nrf')
htdfrpc = HtdfRPC(chaid_id='testchain', rpc_host='192.168.0.171', rpc_port=1317)
hc = HtdfContract(rpc=htdfrpc, address=contract_address, abi=abi)
totalSupply = hc.call(hc.functions.totalSupply())
print(totalSupply)
assert totalSupply == int(199000000 * 10**18)
pass
def test_hrc20_decimals():
with open('./AJC_sol_AJCToken.abi', 'r') as abifile:
# abi = abifile.readlines()
abijson = abifile.read()
# print(abijson)
abi = json.loads(abijson)
contract_address = Address('htdf1k78exwfuta66m3sxgfjd6zuw8m7zykfmas0nrf')
htdfrpc = HtdfRPC(chaid_id='testchain', rpc_host='192.168.0.171', rpc_port=1317)
hc = HtdfContract(rpc=htdfrpc, address=contract_address, abi=abi)
totalSupply = hc.call(hc.functions.decimals())
print(totalSupply)
assert totalSupply == int(18)
pass
def test_hrc20_transfer():
with open('./AJC_sol_AJCToken.abi', 'r') as abifile:
# abi = abifile.readlines()
abijson = abifile.read()
# print(abijson)
abi = json.loads(abijson)
contract_address = Address('htdf1k78exwfuta66m3sxgfjd6zuw8m7zykfmas0nrf')
htdfrpc = HtdfRPC(chaid_id='testchain', rpc_host='192.168.0.171', rpc_port=1317)
hc = HtdfContract(rpc=htdfrpc, address=contract_address, abi=abi)
new_to_addr = HtdfPrivateKey('').address
transfer_tx = hc.functions.transfer(
_to=to_checksum_address(new_to_addr.hex_address),
_value=(10001*10**18)).\
buildTransaction_htdf()
data = remove_0x_prefix(transfer_tx['data'])
from_addr = Address('htdf1xwpsq6yqx0zy6grygy7s395e2646wggufqndml')
private_key = HtdfPrivateKey('279bdcd8dccec91f9e079894da33d6888c0f9ef466c0b200921a1bf1ea7d86e8')
from_acc = htdfrpc.get_account_info(address=from_addr.address)
signed_tx = HtdfTxBuilder(
from_address=from_addr,
to_address=contract_address,
amount_satoshi=0,
sequence=from_acc.sequence,
account_number=from_acc.account_number,
chain_id=htdfrpc.chain_id,
gas_price=100,
gas_wanted=200000,
data=data,
memo='test_hrc20_transfer'
).build_and_sign(private_key=private_key)
tx_hash = htdfrpc.broadcast_tx(tx_hex=signed_tx)
print('tx_hash: {}'.format(tx_hash))
# self.assertTrue( len(tx_hash) == 64)
tx = htdfrpc.get_tranaction_until_timeout(transaction_hash=tx_hash)
pprint(tx)
cfnBalanceOf = hc.functions.balanceOf(_owner=to_checksum_address(new_to_addr.hex_address))
balance = hc.call(cfn=cfnBalanceOf)
print(balance)
pass
TODO
- non-htdfservice transaction(eg. delegate undelegate )
- continuously optimize
- contract event support(HTDF v1.4.0)
- websocket support(HTDF v1.4.0)
More details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
htdfsdk-0.0.18.tar.gz
(153.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
htdfsdk-0.0.18-py3-none-any.whl
(194.2 kB
view details)
File details
Details for the file htdfsdk-0.0.18.tar.gz.
File metadata
- Download URL: htdfsdk-0.0.18.tar.gz
- Upload date:
- Size: 153.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4c20266b2ae093ca61808207406e9609a2e07ad1b325619f8833b3dbedcaec7
|
|
| MD5 |
6881681ffe9deb035f38f114813f10f4
|
|
| BLAKE2b-256 |
3f616c1d654f7f15c0d07602d5ac4c6c752b54f8f0992b9afaecbc4f1786b58b
|
File details
Details for the file htdfsdk-0.0.18-py3-none-any.whl.
File metadata
- Download URL: htdfsdk-0.0.18-py3-none-any.whl
- Upload date:
- Size: 194.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f4ea9461216cfa24a3e4fdb174ca8e9001632dad0cbc090180dc79d4776bc1e
|
|
| MD5 |
6d02bb0bacbdf48f8827ebd8b784f7e2
|
|
| BLAKE2b-256 |
0850b3dc7130960aacf2a11060eb604d79d8219b63070ecbda51ad0884787695
|