本文整理匯總了Python中web3.contract.Contract.encodeABI方法的典型用法代碼示例。如果您正苦於以下問題:Python Contract.encodeABI方法的具體用法?Python Contract.encodeABI怎麽用?Python Contract.encodeABI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web3.contract.Contract
的用法示例。
在下文中一共展示了Contract.encodeABI方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: from web3.contract import Contract [as 別名]
# 或者: from web3.contract.Contract import encodeABI [as 別名]
def execute(
self, to_contract: Contract, func: str, args=None, amount_in_eth: Optional[Decimal] = None, max_gas=100000
):
"""Calls a smart contract from the hosted wallet.
Creates a transaction that is proxyed through hosted wallet execute method. We need to have ABI as Populus Contract instance.
:param wallet_address: Wallet address
:param contract: Contract to called as address bound Populus Contract class
:param func: Method name to be called
:param args: Arguments passed to the method
:param value: Additional value carried in the call in ETH
:param gas: The max amount of gas the coinbase account is allowed to pay for this transaction.
:return: txid of the execution as hex string
"""
assert isinstance(to_contract, Contract)
if amount_in_eth:
assert isinstance(amount_in_eth, Decimal) # Don't let floats slip through
value = to_wei(amount_in_eth)
else:
value = 0
# Encode function arguments
function_abi = to_contract._find_matching_fn_abi(func, args)
# 4 byte function hash
function_selector = function_abi_to_4byte_selector(function_abi)
# data payload passed to the function
arg_data = to_contract.encodeABI(func, args=args)
call_data = function_selector + arg_data[2:]
# test_event_execute() call data should look like
# function selector + random int as 256-bit
# 0x5093dc7d000000000000000000000000000000000000000000000000000000002a3f58fe
# web3 takes bytes argument as actual bytes, not hex
call_data = binascii.unhexlify(call_data[2:])
tx_info = {
# The Ethereum account that pays the gas for this operation
"from": self.contract.web3.eth.coinbase,
"gas": max_gas,
}
txid = self.contract.transact(tx_info).execute(to_contract.address, value, max_gas, call_data)
return txid