A simple web3py like client for APTOS chain.
Project description
APTC: APTOS Client for Python
[WIP] An easier RESTful client for APTOS chain than official python client.
Installation
pip install aptc
# update
pip install -U aptc
Usage
Create a client
from aptc import new_client, APTOS_NODE_URL_LIST, APTClient, HttpxProvider
APT_NODE_URL = APTOS_NODE_URL_LIST[0]
# mainnet
client = new_client(node_url=APT_NODE_URL)
# or
client = APTClient(HttpxProvider(APT_NODE_URL))
# faucet client
client = new_client(faucet=True)
# claim apt from faucet
client.deposit('your address')
Faucet client
The devnet faucet may sometimes not work. Some APIs are not supported by faucet.
from aptc import new_client, Account
account = Account.generate()
print('account address:', account.address())
print('account private key:', account.private_key)
faucet_client = new_client(faucet=True)
txn_hash = faucet_client.deposit(account.address())
print(txn_hash)
Get information from blockchain
more: examples/example1.py
from aptc import new_client, APTClient, HttpxProvider, APTOS_NODE_URL_LIST
client = new_client()
client.get_ledger_info()
client.check_health()
example_address = "0xc739507214d0e1bf9795485299d709e00024e92f7c0d055a4c2c39717882bdfd"
client.get_account(example_address)
client.get_account_balance(example_address)
client.get_account_resources(example_address)
client.get_account_transactions(example_address)
# for some nft mint, get resources is useful to get nft info
# here are one of bluemove nft mint info
some_address = "your address"
# some nft mint factory
some_resource_type = "0xf9bf19f5077c196e5468510e140d1e3cbfa0681f67fe245566ceab2399a6388d::factory::MintedByUser"
client.get_account_resource(some_address, some_resource_type)
Send Transaction
Detail information about transaction, please refer to examples/example2.py
import os
import time
from aptc import Account, APT, new_client
client = new_client()
# submit transaction
# load your private key, environment variable
account = Account.load_key(os.environ['private_key'])
account_address = account.address()
# build a transaction payload
payload = {
'function': '0x1::aptos_account::transfer',
'type_arguments': [],
'arguments': [
"0x8d763223180a2b92f97755a3ea581f1c68d342275ca6118badff663f57aca7a5", # receiver
str(1 * APT) # amount
],
'type': 'entry_function_payload'
}
txn_dict = {
"sender": f"{account_address}",
"sequence_number": str(client.get_account_sequence_number(account_address)),
"max_gas_amount": str(100_000),
"gas_unit_price": str(100),
"expiration_timestamp_secs": str(int(time.time()) + 100),
"payload": payload,
}
# encode this transaction
encoded = client.encode(txn_dict)
# sign this transaction
signature = account.sign(encoded)
txn_dict["signature"] = {
"type": "ed25519_signature",
"public_key": f"{account.public_key()}",
"signature": f"{signature}",
}
# submit transaction
tx = client.submit_transaction(txn_dict)
Ref
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
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
File details
Details for the file aptc-0.0.3.tar.gz.
File metadata
- Download URL: aptc-0.0.3.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
614c2c5c543b9a74f2cbc04f9d862e37656f4dd45b14463eddbffdc3d686297d
|
|
| MD5 |
952a1f7cb0399fa2731c02cc2f7ecfb9
|
|
| BLAKE2b-256 |
75ec7da0794d2c527f2e273528f0fef227a3e160b97c5f37e7f7f231dd9eed73
|
File details
Details for the file aptc-0.0.3-py3-none-any.whl.
File metadata
- Download URL: aptc-0.0.3-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7e1e332b015b34fa7a8cdf1802ee4988dad05657f3246bcf7484c82f2792818
|
|
| MD5 |
2368dc74162655b71f73d5850b20829e
|
|
| BLAKE2b-256 |
c5d2293988050e22f727840db27c8e503c8c86b7b61d6c009d52405656f72e2a
|