Skip to main content

An aide that helps you quickly access the platon chain and use its basic functions.

Project description

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

platon_aide-2.0.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

platon_aide-2.0.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file platon_aide-2.0.1.tar.gz.

File metadata

  • Download URL: platon_aide-2.0.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.16

File hashes

Hashes for platon_aide-2.0.1.tar.gz
Algorithm Hash digest
SHA256 eb6c974ed5c94f6a72cfbd9a19a82aa5429f61e378fe4094fae2a18e6b2eb8db
MD5 09eee3fe2fdea8e60a7c843e2213bf2c
BLAKE2b-256 2126587ad1947760bda42a7a7e48ed86661cea7f0a23ccd7ebe9aeb390a308c1

See more details on using hashes here.

File details

Details for the file platon_aide-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: platon_aide-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.16

File hashes

Hashes for platon_aide-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7af3c0947634edcddaa63064c4823a5d3cfd7bb431ff1bbeb9d98fafaed9480f
MD5 32ed33c2b5566353ef044ab0646aa0aa
BLAKE2b-256 ac5e915142444a518902afa510b267fab562e9aa4bf319ad49f9b96b4f07220c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page