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 platon_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.hrp)
aide.set_default_account(account)
to_account = Account.create(hrp='lat')
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(hrp='lat')
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-1.3.11.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

platon_aide-1.3.11-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file platon-aide-1.3.11.tar.gz.

File metadata

  • Download URL: platon-aide-1.3.11.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for platon-aide-1.3.11.tar.gz
Algorithm Hash digest
SHA256 49bb555161d4d23bb93555da06d0d7feb203d1f360e8b3d73eded55dbdcff674
MD5 bb1d64a58454e77c8aec203cb89aaf4e
BLAKE2b-256 19e9be9d5445c1292fa745d0b3f374da076cc350899c87edc279d5d59bf8bc54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for platon_aide-1.3.11-py3-none-any.whl
Algorithm Hash digest
SHA256 24f694c8329b21385dd071635d0e3c67fb991e1daac1e4530c5160628f9eaff1
MD5 5e1f9fa93dc7541e44ea2379c42d1b18
BLAKE2b-256 95b63103eecc7228c8ba87857d17f46f78d9882c814c4827df496866c17b18c5

See more details on using hashes here.

Supported by

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