Python eth_abi.encode_abi() Examples
The following are 10
code examples of eth_abi.encode_abi().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
eth_abi
, or try the search function
.
Example #1
Source File: contract.py From brownie with MIT License | 6 votes |
def encode_input(self, *args: Tuple) -> str: """ Generate encoded ABI data to call the method with the given arguments. Arguments --------- *args Contract method inputs Returns ------- str Hexstring of encoded ABI data """ data = format_input(self.abi, args) types_list = get_type_strings(self.abi["inputs"]) return self.signature + eth_abi.encode_abi(types_list, data).hex()
Example #2
Source File: conftest.py From clove with GNU General Public License v3.0 | 6 votes |
def web3_request_side_effect(method, params): if method == 'eth_gasPrice': return 20000000000 elif method == 'eth_estimateGas': return 125000 elif method == 'eth_getTransactionCount': return 1 elif method == 'net_version': return 42 elif method == 'eth_blockNumber': return 8400000 elif method == 'eth_call': encoded_abi = encode_abi(abi_swaps_types, non_zero_balance_abi_contract) return encoded_abi.hex() elif method == 'eth_getFilterLogs': return [ { 'data': '0xbc2424e1dcdd2e425c555bcea35a54fd27cf540e60f18366e153e3fb7cf4490c', 'transactionHash': HexBytes('0x65320e57b9d18ec08388896b029ad1495beb7a57c547440253a1dde01b4485f1'), } ] return None
Example #3
Source File: throws_contract.py From eth-tester with MIT License | 6 votes |
def _make_call_throws_transaction(eth_tester, contract_address, contract_name, fn_name, fn_args=None): from eth_abi import encode_abi if fn_args is None: fn_args = tuple() fn_abi = THROWS_ABI[contract_name][fn_name] arg_types = [ arg_abi['type'] for arg_abi in fn_abi['inputs'] ] fn_selector = function_abi_to_4byte_selector(fn_abi) transaction = { "from": eth_tester.get_accounts()[0], "to": contract_address, "gas": 500000, "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)), } return transaction
Example #4
Source File: emitter_contract.py From eth-tester with MIT License | 6 votes |
def _call_emitter(eth_tester, contract_address, fn_name, fn_args): from eth_abi import encode_abi fn_abi = EMITTER_ABI[fn_name] arg_types = [ arg_abi['type'] for arg_abi in fn_abi['inputs'] ] fn_selector = function_abi_to_4byte_selector(fn_abi) emit_a_hash = eth_tester.send_transaction({ "from": eth_tester.get_accounts()[0], "to": contract_address, "gas": 500000, "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)), }) return emit_a_hash
Example #5
Source File: math_contract.py From eth-tester with MIT License | 6 votes |
def _make_call_math_transaction(eth_tester, contract_address, fn_name, fn_args=None): from eth_abi import encode_abi if fn_args is None: fn_args = tuple() fn_abi = MATH_ABI[fn_name] arg_types = [ arg_abi['type'] for arg_abi in fn_abi['inputs'] ] fn_selector = function_abi_to_4byte_selector(fn_abi) transaction = { "from": eth_tester.get_accounts()[0], "to": contract_address, "gas": 500000, "data": encode_hex(fn_selector + encode_abi(arg_types, fn_args)), } return transaction
Example #6
Source File: etherscan_verify.py From raiden-contracts with MIT License | 6 votes |
def _verify_token_networks(chain_id: ChainID, apikey: str) -> None: deployment_file_path = contracts_deployed_path(chain_id=chain_id) with deployment_file_path.open() as f: deployed_contracts_info = json.load(f) token_networks = deployed_contracts_info.get("token_networks", []) with open(contracts_precompiled_path()) as f: contract_dict = json.load(f)["contracts"][CONTRACT_TOKEN_NETWORK] metadata = json.loads(contract_dict["metadata"]) constructor = [func for func in contract_dict["abi"] if func["type"] == "constructor"][0] arg_types = [arg["type"] for arg in constructor["inputs"]] arg_names = [arg["name"] for arg in constructor["inputs"]] for tn in token_networks: args = [tn["constructor_arguments"][arg_name] for arg_name in arg_names] etherscan_verify_contract( chain_id=chain_id, apikey=apikey, address=tn["token_network_address"], contract_name=CONTRACT_TOKEN_NETWORK, metadata=metadata, constructor_args=encode_abi(arg_types, args).hex(), )
Example #7
Source File: contract.py From brownie with MIT License | 5 votes |
def encode_input(self, *args: tuple) -> str: bytecode = self._parent.bytecode # find and replace unlinked library pointers in bytecode for marker in re.findall("_{1,}[^_]*_{1,}", bytecode): library = marker.strip("_") if not self._parent._project[library]: raise UndeployedLibrary( f"Contract requires '{library}' library, but it has not been deployed yet" ) address = self._parent._project[library][-1].address[-40:] bytecode = bytecode.replace(marker, address) data = format_input(self.abi, args) types_list = get_type_strings(self.abi["inputs"]) return bytecode + eth_abi.encode_abi(types_list, data).hex()
Example #8
Source File: pending_transfers.py From raiden-contracts with MIT License | 5 votes |
def get_packed_transfers(pending_transfers: Collection, types: List) -> bytes: packed_transfers: List[bytes] = [encode_abi(types, x[:-1]) for x in pending_transfers] return reduce((lambda x, y: x + y), packed_transfers)
Example #9
Source File: etherscan_verify.py From raiden-contracts with MIT License | 5 votes |
def get_constructor_args( deployment_info: DeployedContracts, contract_name: str, contract_manager: ContractManager ) -> str: constructor_arguments = deployment_info["contracts"][contract_name]["constructor_arguments"] if constructor_arguments != []: constructor_types = contract_manager.get_constructor_argument_types(contract_name) constructor_args = encode_abi(types=constructor_types, args=constructor_arguments).hex() else: constructor_types = [] constructor_args = "" print("constructor_args", constructor_arguments, constructor_types, constructor_args) return constructor_args
Example #10
Source File: zero_ex_transaction_encoder_v3.py From hummingbot with Apache License 2.0 | 5 votes |
def _encode_data(primaryType: str, data: any, types) -> str: encodedTypes = ['bytes32'] encodedValues = [_type_hash(primaryType, types)] for field in types[primaryType]: value = data[field['name']] if field['type'] == 'string': hashValue = keccak(text=value) encodedTypes.append('bytes32') encodedValues.append(hashValue) elif field['type'] == 'bytes': hashValue = keccak(hexstr=value) encodedTypes.append('bytes32') encodedValues.append(hashValue) elif field['type'] in types: encodedTypes.append('bytes32') hashValue = keccak(_encode_data(field['type'], value, types).encode()) encodedValues.append(hashValue) elif field['type'] == 'uint256': encodedTypes.append('uint256') encodedValues.append(int(value)) else: encodedTypes.append(field['type']) normalizedValue = _normalize_value(field['type'], value) encodedValues.append(normalizedValue) return encode_abi(encodedTypes, encodedValues)