前景:基于量化策略需求测试链上转账
Code:
# encoding: UTF-8 """ author: Yorty """ from web3 import Web3 from web3.middleware import geth_poa_middleware
w3 = Web3(Web3.HTTPProvider('your rpc url')) w3.middleware_onion.inject(geth_poa_middleware, layer=0) from_addr = Web3.toChecksumAddress('your address') to_addr = Web3.toChecksumAddress('the address you want to send token to') pk = 'your private key' tx = { 'data': 'Hello my friend', # 自定义data,长度越长gas费越高 'nonce': w3.eth.get_transaction_count(from_addr), # 当前成交序号 'gas': 200000, # gas费用上限 'gasPrice': w3.eth.gas_price, # 当前gas price,可自设,bsc一般最低为5gwei 'value': w3.toWei(1, 'ether'), # send token 数量 'to': to_addr # 发送地址 } signed_tx =