chain-aide


Namechain-aide JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://github.com/shinnng/chain-aide
SummaryAn aide that helps you quickly access mainstream public chain and use its basic functions.
upload_time2023-04-24 01:04:28
maintainer
docs_urlNone
authorShinnng
requires_python
licenseMIT
keywords chain
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # chain-aide
它是一个能够帮助您快速访问各个主流区块链(目前仅支持eth)并使用其功能的小助手 


## 安装方法
```shell
pip install chain_aide
```


## 使用方法

```python
from eth_account import Account
from chain_aide import Aide

uri = 'http://192.168.120.121:6789'
aide = Aide(uri)

# 调用以太坊接口
print(aide.web3.clientVersion)
print(aide.web3.eth.block_number)

# 设置默认账户  
account = Account.from_key('f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74')
aide.set_default_account(account)

"""
指定账户
"""
# 使用设置好的默认账户发送交易
to_account = Account.create()
print(aide.transfer(to_account.address, 10 * 10 ** 18))

# 使用私钥发送交易,比默认账户有更高的优先级
private_key = 'f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74'
print(aide.transfer(to_account.address, 10 * 10 ** 18, private_key=private_key))


"""
发送转账交易
"""
# 发送转账交易,自定义
txn = {'gas': 21000, 'gasPrice': 1 * 10 ** 9, 'nonce': 100}
to_account = Account.create()
print(aide.transfer(to_account.address, 10 * 10 ** 18, txn=txn))

"""
发送合约交易
"""
abi = [{"anonymous": False, "inputs": [{"indexed": False, "internalType": "uint256", "name": "_chainId", "type": "uint256"}], "name": "_putChainID", "type": "event"}, {"inputs": [], "name": "getChainID", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function"}, {"inputs": [], "name": "putChainID", "outputs": [], "stateMutability": "nonpayable", "type": "function"}]
bytecode = '608060405234801561001057600080fd5b50610107806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806336319ab0146037578063564b81ef14603f575b600080fd5b603d6059565b005b60456099565b6040516050919060ae565b60405180910390f35b466000819055507f68e891aec7f9596d6e192c48cb82364ec392d423bce80abd6e1ee5ad05860256600054604051608f919060ae565b60405180910390a1565b600046905090565b60a88160c7565b82525050565b600060208201905060c1600083018460a1565b92915050565b600081905091905056fea264697066735822122037a1668252253271128182c71109922cb1e300fb08a7080a0587f360df4071ba64736f6c63430008060033'

# 部署新的合约
contract = aide.deploy_contract(abi=abi, bytecode=bytecode)
print(contract.address)

# 已有合约,直接初始化
contract_address = '0x'
contract = aide.init_contract(abi=abi, address=contract_address)
print(contract.address)

# call调用
print(contract.getChainID())

# 发送交易(像call调用一样简答)
res = contract.putChainID()

# 解析event
print(contract.PutChainID(res))
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shinnng/chain-aide",
    "name": "chain-aide",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "chain",
    "author": "Shinnng",
    "author_email": "shinnng@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/6d/10/c47d7a22a95ae5906c5adf3866190534439dd2dd423c40d5404875f61852/chain-aide-1.0.5.tar.gz",
    "platform": null,
    "description": "# chain-aide\r\n\u5b83\u662f\u4e00\u4e2a\u80fd\u591f\u5e2e\u52a9\u60a8\u5feb\u901f\u8bbf\u95ee\u5404\u4e2a\u4e3b\u6d41\u533a\u5757\u94fe(\u76ee\u524d\u4ec5\u652f\u6301eth)\u5e76\u4f7f\u7528\u5176\u529f\u80fd\u7684\u5c0f\u52a9\u624b \r\n\r\n\r\n## \u5b89\u88c5\u65b9\u6cd5\r\n```shell\r\npip install chain_aide\r\n```\r\n\r\n\r\n## \u4f7f\u7528\u65b9\u6cd5\r\n\r\n```python\r\nfrom eth_account import Account\r\nfrom chain_aide import Aide\r\n\r\nuri = 'http://192.168.120.121:6789'\r\naide = Aide(uri)\r\n\r\n# \u8c03\u7528\u4ee5\u592a\u574a\u63a5\u53e3\r\nprint(aide.web3.clientVersion)\r\nprint(aide.web3.eth.block_number)\r\n\r\n# \u8bbe\u7f6e\u9ed8\u8ba4\u8d26\u6237  \r\naccount = Account.from_key('f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74')\r\naide.set_default_account(account)\r\n\r\n\"\"\"\r\n\u6307\u5b9a\u8d26\u6237\r\n\"\"\"\r\n# \u4f7f\u7528\u8bbe\u7f6e\u597d\u7684\u9ed8\u8ba4\u8d26\u6237\u53d1\u9001\u4ea4\u6613\r\nto_account = Account.create()\r\nprint(aide.transfer(to_account.address, 10 * 10 ** 18))\r\n\r\n# \u4f7f\u7528\u79c1\u94a5\u53d1\u9001\u4ea4\u6613,\u6bd4\u9ed8\u8ba4\u8d26\u6237\u6709\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7\r\nprivate_key = 'f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74'\r\nprint(aide.transfer(to_account.address, 10 * 10 ** 18, private_key=private_key))\r\n\r\n\r\n\"\"\"\r\n\u53d1\u9001\u8f6c\u8d26\u4ea4\u6613\r\n\"\"\"\r\n# \u53d1\u9001\u8f6c\u8d26\u4ea4\u6613\uff0c\u81ea\u5b9a\u4e49\r\ntxn = {'gas': 21000, 'gasPrice': 1 * 10 ** 9, 'nonce': 100}\r\nto_account = Account.create()\r\nprint(aide.transfer(to_account.address, 10 * 10 ** 18, txn=txn))\r\n\r\n\"\"\"\r\n\u53d1\u9001\u5408\u7ea6\u4ea4\u6613\r\n\"\"\"\r\nabi = [{\"anonymous\": False, \"inputs\": [{\"indexed\": False, \"internalType\": \"uint256\", \"name\": \"_chainId\", \"type\": \"uint256\"}], \"name\": \"_putChainID\", \"type\": \"event\"}, {\"inputs\": [], \"name\": \"getChainID\", \"outputs\": [{\"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\"}], \"stateMutability\": \"view\", \"type\": \"function\"}, {\"inputs\": [], \"name\": \"putChainID\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\"}]\r\nbytecode = '608060405234801561001057600080fd5b50610107806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806336319ab0146037578063564b81ef14603f575b600080fd5b603d6059565b005b60456099565b6040516050919060ae565b60405180910390f35b466000819055507f68e891aec7f9596d6e192c48cb82364ec392d423bce80abd6e1ee5ad05860256600054604051608f919060ae565b60405180910390a1565b600046905090565b60a88160c7565b82525050565b600060208201905060c1600083018460a1565b92915050565b600081905091905056fea264697066735822122037a1668252253271128182c71109922cb1e300fb08a7080a0587f360df4071ba64736f6c63430008060033'\r\n\r\n# \u90e8\u7f72\u65b0\u7684\u5408\u7ea6\r\ncontract = aide.deploy_contract(abi=abi, bytecode=bytecode)\r\nprint(contract.address)\r\n\r\n# \u5df2\u6709\u5408\u7ea6\uff0c\u76f4\u63a5\u521d\u59cb\u5316\r\ncontract_address = '0x'\r\ncontract = aide.init_contract(abi=abi, address=contract_address)\r\nprint(contract.address)\r\n\r\n# call\u8c03\u7528\r\nprint(contract.getChainID())\r\n\r\n# \u53d1\u9001\u4ea4\u6613(\u50cfcall\u8c03\u7528\u4e00\u6837\u7b80\u7b54)\r\nres = contract.putChainID()\r\n\r\n# \u89e3\u6790event\r\nprint(contract.PutChainID(res))\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An aide that helps you quickly access mainstream public chain and use its basic functions.",
    "version": "1.0.5",
    "split_keywords": [
        "chain"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33a8429fcdbcf093bf4de1e3fdeb69826fbc9f7ce5a9482759c83f02a7db546e",
                "md5": "d817acef58df85ebb9635c9da0857189",
                "sha256": "b58ed7109bfbb4b3562469a0203a6fbca1525ce5b0c3eff3b04aeea7fd9151ad"
            },
            "downloads": -1,
            "filename": "chain_aide-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d817acef58df85ebb9635c9da0857189",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7820,
            "upload_time": "2023-04-24T01:04:22",
            "upload_time_iso_8601": "2023-04-24T01:04:22.943525Z",
            "url": "https://files.pythonhosted.org/packages/33/a8/429fcdbcf093bf4de1e3fdeb69826fbc9f7ce5a9482759c83f02a7db546e/chain_aide-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d10c47d7a22a95ae5906c5adf3866190534439dd2dd423c40d5404875f61852",
                "md5": "002aa4f367e52a77b317977889d90bd8",
                "sha256": "8b1194e17f73cde1b4cb482b8b0a5351ef0013762313ff5453d01a879001d759"
            },
            "downloads": -1,
            "filename": "chain-aide-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "002aa4f367e52a77b317977889d90bd8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7069,
            "upload_time": "2023-04-24T01:04:28",
            "upload_time_iso_8601": "2023-04-24T01:04:28.415665Z",
            "url": "https://files.pythonhosted.org/packages/6d/10/c47d7a22a95ae5906c5adf3866190534439dd2dd423c40d5404875f61852/chain-aide-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-24 01:04:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "shinnng",
    "github_project": "chain-aide",
    "lcname": "chain-aide"
}
        
Elapsed time: 1.07663s