def get_constructor_arguments(contract: Contract, args: Optional[list] = None, kwargs: Optional[dict] = None): """Get constructor arguments for Etherscan verify. https://etherscanio.freshdesk.com/support/solutions/articles/16000053599-contract-verification-constructor-arguments """ # return contract._encode_constructor_data(args=args, kwargs=kwargs) constructor_abi = get_constructor_abi(contract.abi) if args is not None: return contract._encode_constructor_data(args=args, kwargs=kwargs) else: constructor_abi = get_constructor_abi(contract.abi) kwargs = kwargs or {} arguments = merge_args_and_kwargs(constructor_abi, [], kwargs) # deploy_data = add_0x_prefix( # contract._encode_abi(constructor_abi, arguments) #) # TODO: Looks like recent Web3.py ABI change deploy_data = encode_abi(contract.web3, constructor_abi, arguments) return deploy_data
def encodeABI(cls, fn_name, args=None, kwargs=None, data=None): """ Encodes the arguments using the Ethereum ABI for the contract function that matches the given name and arguments.. :param data: defaults to function selector """ fn_abi, fn_selector, fn_arguments = get_function_info( cls.abi, fn_name, args, kwargs, ) if data is None: data = fn_selector return encode_abi(cls.web3, fn_abi, fn_arguments, data)
def _encode_data_in_transaction(self, *args, **kwargs): constructor_abi = get_constructor_abi(self.abi) if constructor_abi: if not args: args = tuple() if not kwargs: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) data = add_0x_prefix( encode_abi(self.web3, constructor_abi, arguments, data=self.bytecode) ) else: data = to_hex(self.bytecode) return data
def _encode_constructor_data(cls, args=None, kwargs=None): constructor_abi = get_constructor_abi(cls.abi) if constructor_abi: if args is None: args = tuple() if kwargs is None: kwargs = {} arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) deploy_data = add_0x_prefix( encode_abi(cls.web3, constructor_abi, arguments, data=cls.bytecode) ) else: deploy_data = to_hex(cls.bytecode) return deploy_data
def from_signature(cls, fn_sign: str, fn_args: list): """ Allow to create a `Calldata` from a function signature and a list of arguments. :param fn_sign: the function signature ie. "function(uint256,address)" :param fn_args: arguments to the function ie. [123, "0x00...00"] :return: """ assert isinstance(fn_sign, str) assert isinstance(fn_args, list) fn_split = re.split('\W+', fn_sign) fn_name = fn_split[0] fn_args_type = [{"type": type} for type in fn_split[1:] if type] fn_abi = {"type": "function", "name": fn_name, "inputs": fn_args_type} fn_abi, fn_selector, fn_arguments = get_function_info("test", fn_abi=fn_abi, args=fn_args) calldata = encode_abi(Web3, fn_abi, fn_arguments, fn_selector) return cls(calldata)
def _encode_transaction_data(cls): return add_0x_prefix( encode_abi(cls.web3, cls.abi, cls.arguments, cls.selector))
def _encode_transaction_data(cls): return add_0x_prefix(encode_abi(cls.web3, cls.abi, cls.arguments, cls.selector))