Package org.web3j.tx

Class Contract

  • Direct Known Subclasses:
    ENS, PublicResolver

    public abstract class Contract
    extends ManagedTransaction
    Solidity contract type abstraction for interacting with smart contracts via native Java types.
    • Field Detail

      • GAS_LIMIT

        public static final java.math.BigInteger GAS_LIMIT
        Deprecated.
        ...
        See Also:
        DefaultGasProvider
      • BIN_NOT_PROVIDED

        public static final java.lang.String BIN_NOT_PROVIDED
        See Also:
        Constant Field Values
      • contractBinary

        protected final java.lang.String contractBinary
      • contractAddress

        protected java.lang.String contractAddress
      • deployedAddresses

        protected java.util.Map<java.lang.String,​java.lang.String> deployedAddresses
    • Constructor Detail

      • Contract

        protected Contract​(java.lang.String contractBinary,
                           java.lang.String contractAddress,
                           Web3j web3j,
                           org.web3j.crypto.Credentials credentials,
                           ContractGasProvider gasProvider)
      • Contract

        @Deprecated
        protected Contract​(java.lang.String contractBinary,
                           java.lang.String contractAddress,
                           Web3j web3j,
                           TransactionManager transactionManager,
                           java.math.BigInteger gasPrice,
                           java.math.BigInteger gasLimit)
        Deprecated.
      • Contract

        @Deprecated
        protected Contract​(java.lang.String contractBinary,
                           java.lang.String contractAddress,
                           Web3j web3j,
                           org.web3j.crypto.Credentials credentials,
                           java.math.BigInteger gasPrice,
                           java.math.BigInteger gasLimit)
        Deprecated.
      • Contract

        @Deprecated
        protected Contract​(java.lang.String contractAddress,
                           Web3j web3j,
                           TransactionManager transactionManager,
                           java.math.BigInteger gasPrice,
                           java.math.BigInteger gasLimit)
        Deprecated.
      • Contract

        @Deprecated
        protected Contract​(java.lang.String contractAddress,
                           Web3j web3j,
                           org.web3j.crypto.Credentials credentials,
                           java.math.BigInteger gasPrice,
                           java.math.BigInteger gasLimit)
        Deprecated.
    • Method Detail

      • setContractAddress

        public void setContractAddress​(java.lang.String contractAddress)
      • getContractAddress

        public java.lang.String getContractAddress()
      • setTransactionReceipt

        public void setTransactionReceipt​(TransactionReceipt transactionReceipt)
      • getContractBinary

        public java.lang.String getContractBinary()
      • setGasPrice

        public void setGasPrice​(java.math.BigInteger newPrice)
        Deprecated.
        use ContractGasProvider
        Allow gasPrice to be set.
        Parameters:
        newPrice - gas price to use for subsequent transactions
      • getGasPrice

        public java.math.BigInteger getGasPrice()
        Deprecated.
        use ContractGasProvider
        Get the current gasPrice value this contract uses when executing transactions.
        Returns:
        the gas price set on this contract
      • isValid

        public boolean isValid()
                        throws java.io.IOException
        Check that the contract deployed at the address associated with this smart contract wrapper is in fact the contract you believe it is.

        This method uses the eth_getCode method to get the contract byte code and validates it against the byte code stored in this smart contract wrapper.

        Returns:
        true if the contract is valid
        Throws:
        java.io.IOException - if unable to connect to web3j node
      • getTransactionReceipt

        public java.util.Optional<TransactionReceipt> getTransactionReceipt()
        If this Contract instance was created at deployment, the TransactionReceipt associated with the initial creation will be provided, e.g. via a deploy method. This will not persist for Contracts instances constructed via a load method.
        Returns:
        the TransactionReceipt generated at contract deployment
      • setDefaultBlockParameter

        public void setDefaultBlockParameter​(DefaultBlockParameter defaultBlockParameter)
        Sets the default block parameter. This use useful if one wants to query historical state of a contract.
        Parameters:
        defaultBlockParameter - the default block parameter
      • executeCallSingleValueReturn

        protected <T extends org.web3j.abi.datatypes.Type> T executeCallSingleValueReturn​(org.web3j.abi.datatypes.Function function)
                                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • executeCallSingleValueReturn

        protected <T extends org.web3j.abi.datatypes.Type,​R> R executeCallSingleValueReturn​(org.web3j.abi.datatypes.Function function,
                                                                                                  java.lang.Class<R> returnType)
                                                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • executeCallMultipleValueReturn

        protected java.util.List<org.web3j.abi.datatypes.Type> executeCallMultipleValueReturn​(org.web3j.abi.datatypes.Function function)
                                                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • executeRemoteCallSingleValueReturn

        protected <T extends org.web3j.abi.datatypes.Type> RemoteFunctionCall<T> executeRemoteCallSingleValueReturn​(org.web3j.abi.datatypes.Function function)
      • executeRemoteCallSingleValueReturn

        protected <T> RemoteFunctionCall<T> executeRemoteCallSingleValueReturn​(org.web3j.abi.datatypes.Function function,
                                                                               java.lang.Class<T> returnType)
      • executeRemoteCallMultipleValueReturn

        protected RemoteFunctionCall<java.util.List<org.web3j.abi.datatypes.Type>> executeRemoteCallMultipleValueReturn​(org.web3j.abi.datatypes.Function function)
      • executeRemoteCallTransaction

        protected RemoteFunctionCall<TransactionReceipt> executeRemoteCallTransaction​(org.web3j.abi.datatypes.Function function,
                                                                                      java.math.BigInteger weiValue)
      • deploy

        protected static <T extends Contract> T deploy​(java.lang.Class<T> type,
                                                       Web3j web3j,
                                                       org.web3j.crypto.Credentials credentials,
                                                       ContractGasProvider contractGasProvider,
                                                       java.lang.String binary,
                                                       java.lang.String encodedConstructor,
                                                       java.math.BigInteger value)
                                                throws java.lang.RuntimeException,
                                                       TransactionException
        Throws:
        java.lang.RuntimeException
        TransactionException
      • deploy

        @Deprecated
        protected static <T extends Contract> T deploy​(java.lang.Class<T> type,
                                                       Web3j web3j,
                                                       org.web3j.crypto.Credentials credentials,
                                                       java.math.BigInteger gasPrice,
                                                       java.math.BigInteger gasLimit,
                                                       java.lang.String binary,
                                                       java.lang.String encodedConstructor,
                                                       java.math.BigInteger value)
                                                throws java.lang.RuntimeException,
                                                       TransactionException
        Deprecated.
        Throws:
        java.lang.RuntimeException
        TransactionException
      • deploy

        @Deprecated
        protected static <T extends Contract> T deploy​(java.lang.Class<T> type,
                                                       Web3j web3j,
                                                       TransactionManager transactionManager,
                                                       java.math.BigInteger gasPrice,
                                                       java.math.BigInteger gasLimit,
                                                       java.lang.String binary,
                                                       java.lang.String encodedConstructor,
                                                       java.math.BigInteger value)
                                                throws java.lang.RuntimeException,
                                                       TransactionException
        Deprecated.
        Throws:
        java.lang.RuntimeException
        TransactionException
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          org.web3j.crypto.Credentials credentials,
                                                                          java.math.BigInteger gasPrice,
                                                                          java.math.BigInteger gasLimit,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor,
                                                                          java.math.BigInteger value)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          org.web3j.crypto.Credentials credentials,
                                                                          java.math.BigInteger gasPrice,
                                                                          java.math.BigInteger gasLimit,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          org.web3j.crypto.Credentials credentials,
                                                                          ContractGasProvider contractGasProvider,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor,
                                                                          java.math.BigInteger value)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          org.web3j.crypto.Credentials credentials,
                                                                          ContractGasProvider contractGasProvider,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          TransactionManager transactionManager,
                                                                          java.math.BigInteger gasPrice,
                                                                          java.math.BigInteger gasLimit,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor,
                                                                          java.math.BigInteger value)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          TransactionManager transactionManager,
                                                                          java.math.BigInteger gasPrice,
                                                                          java.math.BigInteger gasLimit,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor)
      • deployRemoteCall

        public static <T extends ContractRemoteCall<T> deployRemoteCall​(java.lang.Class<T> type,
                                                                          Web3j web3j,
                                                                          TransactionManager transactionManager,
                                                                          ContractGasProvider contractGasProvider,
                                                                          java.lang.String binary,
                                                                          java.lang.String encodedConstructor,
                                                                          java.math.BigInteger value)
      • staticExtractEventParameters

        public static org.web3j.abi.EventValues staticExtractEventParameters​(org.web3j.abi.datatypes.Event event,
                                                                             Log log)
      • resolveContractAddress

        protected java.lang.String resolveContractAddress​(java.lang.String contractAddress)
      • extractEventParameters

        protected org.web3j.abi.EventValues extractEventParameters​(org.web3j.abi.datatypes.Event event,
                                                                   Log log)
      • extractEventParameters

        protected java.util.List<org.web3j.abi.EventValues> extractEventParameters​(org.web3j.abi.datatypes.Event event,
                                                                                   TransactionReceipt transactionReceipt)
      • extractEventParametersWithLog

        protected Contract.EventValuesWithLog extractEventParametersWithLog​(org.web3j.abi.datatypes.Event event,
                                                                            Log log)
      • staticExtractEventParametersWithLog

        protected static Contract.EventValuesWithLog staticExtractEventParametersWithLog​(org.web3j.abi.datatypes.Event event,
                                                                                         Log log)
      • getStaticDeployedAddress

        protected java.lang.String getStaticDeployedAddress​(java.lang.String networkId)
        Subclasses should implement this method to return pre-existing addresses for deployed contracts.
        Parameters:
        networkId - the network id, for example "1" for the main-net, "3" for ropsten, etc.
        Returns:
        the deployed address of the contract, if known, and null otherwise.
      • setDeployedAddress

        public final void setDeployedAddress​(java.lang.String networkId,
                                             java.lang.String address)
      • getDeployedAddress

        public final java.lang.String getDeployedAddress​(java.lang.String networkId)
      • convertToNative

        protected static <S extends org.web3j.abi.datatypes.Type,​T> java.util.List<T> convertToNative​(java.util.List<S> arr)