The Python Client SDK for Starcoin
Project description
starcoin-sdk-python
Document
The document of starcoin sdk for python: documents site.
Dependency
$python -V Python 3.8.5
Install
python setup.py install
Usage
from starcoin import starcoin_types as types
from starcoin import starcoin_stdlib as stdlib
from starcoin import serde_types as st
from starcoin.sdk import (utils, client, local_account, auth_key)
from starcoin.sdk.receipt_identifier import ReceiptIdentifier
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey, Ed25519PublicKey)
# create a client for connecting starcoin node
cli = client.Client("https://barnard-seed.starcoin.org")
# get the node info
print(cli.node_info())
# get the resource of account
account_resource = cli.state_get(
'0x00000000000000000000000000000001/1/0x00000000000000000000000000000001::Account::Account')
print(account_resource)
# create a account with your private key
private_key = Ed25519PrivateKey.from_private_bytes(bytes.fromhex(
"e424e16db235e3f3b9ef2475516c51d4c15aa5287ceb364213698bd551eab4f2"))
account = local_account.LocalAccount(private_key)
# define a transfer function
def transfer(cli: client.Client, sender: local_account.LocalAccount, receipt: str, amount: st.uint128):
seq_num = cli.get_account_sequence(
"0x"+sender.account_address.bcs_serialize().hex())
receipt = ReceiptIdentifier.decode(receipt)
script = stdlib.encode_peer_to_peer_v2_script_function(
token_type=utils.currency_code("STC"),
payee=receipt.account_address,
amount=amount,
)
node_info = cli.node_info()
now_seconds = int(node_info.get('now_seconds'))
# expired after 12 hours
expiration_timestamp_secs = now_seconds + 43200
raw_txn = types.RawTransaction(
sender=sender.account_address,
sequence_number=seq_num,
payload=script,
max_gas_amount=10000000,
gas_unit_price=1,
gas_token_code="0x1::STC::STC",
expiration_timestamp_secs=expiration_timestamp_secs,
chain_id=types.ChainId(st.uint8(251)),
)
txn = sender.sign(raw_txn)
print(cli.submit(txn))
More examples see examples
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
starcoin-sdk-python-1.4.0.tar.gz
(28.4 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
File details
Details for the file starcoin-sdk-python-1.4.0.tar.gz.
File metadata
- Download URL: starcoin-sdk-python-1.4.0.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc5a1fa79c41cc0c4caf88d2ddc84075ffe34cc0c3886eae5461ac0403d86586
|
|
| MD5 |
c4db3f8111c40043e7a46c6eefbfe833
|
|
| BLAKE2b-256 |
a5416828a9e6552f8162855607d0efde88fd0aadf3501da22eca7c583e6f8feb
|
File details
Details for the file starcoin_sdk_python-1.4.0-py3-none-any.whl.
File metadata
- Download URL: starcoin_sdk_python-1.4.0-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
892f24dd475043386e0b47558e04de37aa200dc880fb90ad9dbe4e2fb6f97144
|
|
| MD5 |
c8457f19bdafa3b0307cb592e1e40857
|
|
| BLAKE2b-256 |
64c207f5f33c44a900b6322524fa2c98f15f428091435326e25e2bbcc9fa269a
|