aptc


Nameaptc JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/ackness/aptc
SummaryA simple web3py like client for APTOS chain.
upload_time2023-02-09 12:30:55
maintainer
docs_urlNone
authorYong
requires_python>=3.7
licenseMIT
keywords apt aptos block chain web3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # APTC: APTOS Client for Python

![Version](https://img.shields.io/badge/aptc-v0.0.2-green)
![GitHub Org's stars](https://img.shields.io/github/stars/ackness/aptc?style=social)
![GitHub forks](https://img.shields.io/github/forks/ackness/aptc?style=social)
![Pypi](https://img.shields.io/pypi/dm/aptc)

---

[WIP] An easier RESTful client for APTOS chain than [official python client](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/README.md).

---

## Installation

```bash
pip install aptc

# update
pip install -U aptc
```

## Usage

### Create a client

```python
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.

```python
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](https://github.com/ackness/aptc/blob/main/examples/example1.py)


```python
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](https://github.com/ackness/aptc/blob/main/examples/example2.py)

```python
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

1. [Aptos Node API](https://fullnode.devnet.aptoslabs.com/v1/spec#/)
2. [Aptos Python SDK](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/README.md)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ackness/aptc",
    "name": "aptc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "apt,aptos,block chain,web3",
    "author": "Yong",
    "author_email": "ackness8@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/75/ec/7da0794d2c527f2e273528f0fef227a3e160b97c5f37e7f7f231dd9eed73/aptc-0.0.3.tar.gz",
    "platform": null,
    "description": "# APTC: APTOS Client for Python\n\n![Version](https://img.shields.io/badge/aptc-v0.0.2-green)\n![GitHub Org's stars](https://img.shields.io/github/stars/ackness/aptc?style=social)\n![GitHub forks](https://img.shields.io/github/forks/ackness/aptc?style=social)\n![Pypi](https://img.shields.io/pypi/dm/aptc)\n\n---\n\n[WIP] An easier RESTful client for APTOS chain than [official python client](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/README.md).\n\n---\n\n## Installation\n\n```bash\npip install aptc\n\n# update\npip install -U aptc\n```\n\n## Usage\n\n### Create a client\n\n```python\nfrom aptc import new_client, APTOS_NODE_URL_LIST, APTClient, HttpxProvider\n\nAPT_NODE_URL = APTOS_NODE_URL_LIST[0]\n\n# mainnet\nclient = new_client(node_url=APT_NODE_URL)\n# or\nclient = APTClient(HttpxProvider(APT_NODE_URL))\n\n# faucet client\nclient = new_client(faucet=True)\n# claim apt from faucet\nclient.deposit('your address')\n\n```\n\n### Faucet client\n\nThe devnet faucet may sometimes not work. Some APIs are not supported by faucet.\n\n```python\nfrom aptc import new_client, Account\n\naccount = Account.generate()\n\nprint('account address:', account.address())\nprint('account private key:', account.private_key)\n\nfaucet_client = new_client(faucet=True)\ntxn_hash = faucet_client.deposit(account.address())\nprint(txn_hash)\n```\n\n\n### Get information from blockchain\n\nmore: [examples/example1.py](https://github.com/ackness/aptc/blob/main/examples/example1.py)\n\n\n```python\nfrom aptc import new_client, APTClient, HttpxProvider, APTOS_NODE_URL_LIST\n\nclient = new_client()\n\nclient.get_ledger_info()\nclient.check_health()\n\nexample_address = \"0xc739507214d0e1bf9795485299d709e00024e92f7c0d055a4c2c39717882bdfd\"\nclient.get_account(example_address)\nclient.get_account_balance(example_address)\nclient.get_account_resources(example_address)\nclient.get_account_transactions(example_address)\n\n# for some nft mint, get resources is useful to get nft info\n# here are one of bluemove nft mint info\nsome_address = \"your address\"\n# some nft mint factory\nsome_resource_type = \"0xf9bf19f5077c196e5468510e140d1e3cbfa0681f67fe245566ceab2399a6388d::factory::MintedByUser\"\nclient.get_account_resource(some_address, some_resource_type)\n```\n\n### Send Transaction\n\nDetail information about transaction, please refer to [examples/example2.py](https://github.com/ackness/aptc/blob/main/examples/example2.py)\n\n```python\nimport os\nimport time\nfrom aptc import Account, APT, new_client\n\n\nclient = new_client()\n\n# submit transaction\n# load your private key, environment variable\naccount = Account.load_key(os.environ['private_key'])\naccount_address = account.address()\n\n# build a transaction payload\npayload = {\n    'function': '0x1::aptos_account::transfer',\n    'type_arguments': [],\n    'arguments': [\n        \"0x8d763223180a2b92f97755a3ea581f1c68d342275ca6118badff663f57aca7a5\",  # receiver\n        str(1 * APT)  # amount\n    ],\n    'type': 'entry_function_payload'\n}\n\ntxn_dict = {\n    \"sender\": f\"{account_address}\",\n    \"sequence_number\": str(client.get_account_sequence_number(account_address)),\n    \"max_gas_amount\": str(100_000),\n    \"gas_unit_price\": str(100),\n    \"expiration_timestamp_secs\": str(int(time.time()) + 100),\n    \"payload\": payload,\n}\n\n# encode this transaction\nencoded = client.encode(txn_dict)\n# sign this transaction\nsignature = account.sign(encoded)\n\ntxn_dict[\"signature\"] = {\n    \"type\": \"ed25519_signature\",\n    \"public_key\": f\"{account.public_key()}\",\n    \"signature\": f\"{signature}\",\n}\n\n# submit transaction\ntx = client.submit_transaction(txn_dict)\n```\n\n\n## Ref\n\n1. [Aptos Node API](https://fullnode.devnet.aptoslabs.com/v1/spec#/)\n2. [Aptos Python SDK](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/README.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple web3py like client for APTOS chain.",
    "version": "0.0.3",
    "split_keywords": [
        "apt",
        "aptos",
        "block chain",
        "web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c5d2293988050e22f727840db27c8e503c8c86b7b61d6c009d52405656f72e2a",
                "md5": "2368dc74162655b71f73d5850b20829e",
                "sha256": "a7e1e332b015b34fa7a8cdf1802ee4988dad05657f3246bcf7484c82f2792818"
            },
            "downloads": -1,
            "filename": "aptc-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2368dc74162655b71f73d5850b20829e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19430,
            "upload_time": "2023-02-09T12:30:54",
            "upload_time_iso_8601": "2023-02-09T12:30:54.140431Z",
            "url": "https://files.pythonhosted.org/packages/c5/d2/293988050e22f727840db27c8e503c8c86b7b61d6c009d52405656f72e2a/aptc-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75ec7da0794d2c527f2e273528f0fef227a3e160b97c5f37e7f7f231dd9eed73",
                "md5": "952a1f7cb0399fa2731c02cc2f7ecfb9",
                "sha256": "614c2c5c543b9a74f2cbc04f9d862e37656f4dd45b14463eddbffdc3d686297d"
            },
            "downloads": -1,
            "filename": "aptc-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "952a1f7cb0399fa2731c02cc2f7ecfb9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 16518,
            "upload_time": "2023-02-09T12:30:55",
            "upload_time_iso_8601": "2023-02-09T12:30:55.272288Z",
            "url": "https://files.pythonhosted.org/packages/75/ec/7da0794d2c527f2e273528f0fef227a3e160b97c5f37e7f7f231dd9eed73/aptc-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-09 12:30:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ackness",
    "github_project": "aptc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "aptc"
}
        
Elapsed time: 0.05127s