A python wrapper for tv api.
For more detail, please refer:
PYTVSPOS User Guide Specification (English)
- clone the repo under you workspace
git clone https://github.com/tivalueproject/pytvspos
- install packages in pytvspos/requirement.txt by
pip install -r ./pytvspos/requirements.txt
- Then you can
import pytvspos
in your workspace
-
For testnet:
import pytvspos as pv ts_chain = pv.testnet_chain()
-
For default chain:
import pytvspos as pv main_chain = pv.default_chain()
-
For custom api node:
import pytvspos as pv custom_wrapper = pv.create_api_wrapper('http://<full node ip>:9122', api_key='') ts_chain = pv.testnet_chain(custom_wrapper)
-
For completely custom chain:
import pytvspos as pv custom_wrapper = pv.create_api_wrapper('http://<full node ip>:9122', api_key='') t_chain = pv.Chain(chain_name='testnet', chain_id='T', address_version=29, api_wrapper=custom_wrapper) custom_wrapper2 = pv.create_api_wrapper('http://<full node ip>:9122', api_key='') m_chain = pv.Chain(chain_name='mainnet', chain_id=';', address_version=29, api_wrapper=custom_wrapper2) custom_wrapper3 = pv.create_api_wrapper('http://<full node ip>:9122', api_key='') c_chain = pv.Chain(chain_name='mychain', chain_id='C', address_version=29, api_wrapper=custom_wrapper3)
-
look up current block height of the chain:
ts_chain.height()
-
look up the last block info of the chain:
ts_chain.lastblock()
-
look up a block info at n in the chain:
ts_chain.block(n)
-
Get a transaction info by transacion id in the chain:
ts_chain.tx(tx_id)
-
Validate an address of the chain:
ts_chain.validate_address(addr)
- constructed by seed
from pytvspos import Account my_address = Account(chain=ts_chain, seed='<your seed>', nonce=0)
- constructed by private key
from pytvspos import Account my_address = Account(chain=ts_chain, private_key='<your base58 private key>')
- constructed by public key
from pytvspos import Account recipient = Account(chain=ts_chain, public_key='<base58 public key>')
- constructed by wallet address
from pytvspos import Account recipient = Account(chain=ts_chain, address='<base58 wallet address>')
- Get balance
# get balance balance = my_address.balance() print("The balance is {}".format(balance)) # get balance after 16 confirmations balance = my_address.balance(confirmations = 16) print("The balance is {}".format(balance))
- Send payment transaction
# send payment (100000000 = 1 TV) my_address.send_payment(recipient, amount=100000000)
- Send and cancel lease transaction
# send lease (100000000 = 1 TV) response = my_address.lease(recipient, amount=100000000) tx_id = response["id"] # cancel lease my_address.lease_cancel(tx_id)
Sample code for reference