Skip to main content

platon-aide

它是一个小助手,能够帮助您快速访问PlatON区块链,并使用其基本功能

安装方法

pip install platon_aide

使用方法

from eth_account import Account

from platon_aide import Aide
from platon_aide.economic import new_economic

uri = 'http://192.168.120.121:6789'

"""
初始化部分
"""
# 实例化aide
aide = Aide(uri)

# 特殊情况实例化aide
# 这里因为节点关闭了admin、debug的api,aide将无法自动获取经济模型参数和节点信息
# 为了避免aide自动获取报错,需要自己生成经济模型对象,并指定关闭的接口
data = {"common": {"maxEpochMinutes": 3, "nodeBlockTimeWindow": 10, "perRoundBlocks": 10, "maxConsensusVals": 4, "additionalCycleTime": 28},
        "staking": {"stakeThreshold": 100000000000000000000000, "operatingThreshold": 10000000000000000000, "maxValidators": 5, "unStakeFreezeDuration": 2,
                    "rewardPerMaxChangeRange": 500, "rewardPerChangeInterval": 2},
        "slashing": {"slashFractionDuplicateSign": 100, "duplicateSignReportReward": 50, "maxEvidenceAge": 1, "slashBlocksReward": 5, "zeroProduceCumulativeTime": 1,
                     "zeroProduceNumberThreshold": 1, "zeroProduceFreezeDuration": 1},
        "gov": {"versionProposalVoteDurationSeconds": 1600, "versionProposalSupportRate": 6670, "textProposalVoteDurationSeconds": 160, "textProposalVoteRate": 5000,
                "textProposalSupportRate": 6670, "cancelProposalVoteRate": 5000, "cancelProposalSupportRate": 6670, "paramProposalVoteDurationSeconds": 160,
                "paramProposalVoteRate": 5000, "paramProposalSupportRate": 6670},
        "reward": {"newBlockRate": 50, "platonFoundationYear": 10, "increaseIssuanceRatio": 250, "theNumberOfDelegationsReward": 2},
        "restricting": {"minimumRelease": 100000000000000000000},
        "innerAcc": {"platonFundAccount": "lat1drz94my95tskswnrcnkdvnwq43n8jt6dmzf8h8", "platonFundBalance": 0, "cdfAccount": "lat1kvurep20767ahvrkraglgd9t34w0w2g059pmlx",
                     "cdfBalance": 421411981000000000000000000}}
economic = new_economic(data)
aide = Aide(uri, economic=economic, exclude_api=['admin', 'debug'])

"""
交易签名部分
"""
# 设置默认账户,后续使用aide发交易,如果不指定私钥,则都会使用默认账户签名交易
account = Account.from_key('f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74')
aide.set_default_account(account)
to_account = Account.create()
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))

# 使用特定私钥签名,附带自主指定交易信息方法
txn = {'gas': 21000, 'gasPrice': 1 * 10 ** 9, 'nonce': 100}
private_key = 'f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74'
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18, txn=txn, private_key=private_key))

"""
普通交易部分
"""
# 发送转账
to_account = Account.create()
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))

# 调用web3
print(aide.web3.clientVersion)

# 调用内置合约
print(aide.delegate.get_delegate_lock_info())

"""
调用合约部分
"""
false = False
ture = True
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.contract.deploy(abi=abi, bytecode=bytecode)
print(contract.ADDRESS)

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

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

# 发送交易,和call一样
res = aide.contract.putChainID()

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

Metadata

Release files for platon-aide 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for platon-aide 2.0.1
File Size Uploaded Provenance Actions
platon_aide-2.0.1.tar.gz 21.6 kB Without provenance Details for platon_aide-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for platon-aide 2.0.1
File Interpreter ABI Platform Actions
platon_aide-2.0.1-py3-none-any.whl Python 3 none any Details for platon_aide-2.0.1-py3-none-any.whl

Total release size: 45.6 kB

Release files / platon_aide-2.0.1.tar.gz

Download URL platon_aide-2.0.1.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eb6c974ed5c94f6a72cfbd9a19a82aa5429f61e378fe4094fae2a18e6b2eb8db
BLAKE2b-256 checksum
How to use checksums
2126587ad1947760bda42a7a7e48ed86661cea7f0a23ccd7ebe9aeb390a308c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.16

Release files / platon_aide-2.0.1-py3-none-any.whl

Download URL platon_aide-2.0.1-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7af3c0947634edcddaa63064c4823a5d3cfd7bb431ff1bbeb9d98fafaed9480f
BLAKE2b-256 checksum
How to use checksums
ac5e915142444a518902afa510b267fab562e9aa4bf319ad49f9b96b4f07220c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.16

Security for platon-aide 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page