Package org.web3j.tx
Class Contract
- java.lang.Object
-
- org.web3j.tx.ManagedTransaction
-
- org.web3j.tx.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContract.EventValuesWithLogAdds a log field toEventValues.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBIN_NOT_PROVIDEDprotected java.lang.StringcontractAddressprotected java.lang.StringcontractBinaryprotected DefaultBlockParameterdefaultBlockParameterprotected java.util.Map<java.lang.String,java.lang.String>deployedAddressesstatic java.lang.StringFUNC_DEPLOYstatic java.math.BigIntegerGAS_LIMITDeprecated....protected ContractGasProvidergasProviderprotected TransactionReceipttransactionReceipt-
Fields inherited from class org.web3j.tx.ManagedTransaction
ensResolver, GAS_PRICE, transactionManager, web3j
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedContract(java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, java.math.BigInteger gasPrice, java.math.BigInteger gasLimit)Deprecated.protectedContract(java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider gasProvider)protectedContract(java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, java.math.BigInteger gasPrice, java.math.BigInteger gasLimit)Deprecated.protectedContract(java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider)protectedContract(java.lang.String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, java.math.BigInteger gasPrice, java.math.BigInteger gasLimit)Deprecated.protectedContract(java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, java.math.BigInteger gasPrice, java.math.BigInteger gasLimit)Deprecated.protectedContract(EnsResolver ensResolver, java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static <S extends org.web3j.abi.datatypes.Type,T>
java.util.List<T>convertToNative(java.util.List<S> arr)protected static <T extends Contract>
Tdeploy(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)Deprecated.protected static <T extends Contract>
Tdeploy(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)protected static <T extends Contract>
Tdeploy(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)Deprecated.protected static <T extends Contract>
Tdeploy(java.lang.Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, java.lang.String binary, java.lang.String encodedConstructor, java.math.BigInteger value)static <T extends Contract>
RemoteCall<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)static <T extends Contract>
RemoteCall<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)static <T extends Contract>
RemoteCall<T>deployRemoteCall(java.lang.Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, java.lang.String binary, java.lang.String encodedConstructor)static <T extends Contract>
RemoteCall<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)static <T extends Contract>
RemoteCall<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)static <T extends Contract>
RemoteCall<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)static <T extends Contract>
RemoteCall<T>deployRemoteCall(java.lang.Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, java.lang.String binary, java.lang.String encodedConstructor)static <T extends Contract>
RemoteCall<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)protected java.util.List<org.web3j.abi.datatypes.Type>executeCallMultipleValueReturn(org.web3j.abi.datatypes.Function function)protected <T extends org.web3j.abi.datatypes.Type>
TexecuteCallSingleValueReturn(org.web3j.abi.datatypes.Function function)protected <T extends org.web3j.abi.datatypes.Type,R>
RexecuteCallSingleValueReturn(org.web3j.abi.datatypes.Function function, java.lang.Class<R> returnType)protected RemoteFunctionCall<java.util.List<org.web3j.abi.datatypes.Type>>executeRemoteCallMultipleValueReturn(org.web3j.abi.datatypes.Function function)protected <T extends org.web3j.abi.datatypes.Type>
RemoteFunctionCall<T>executeRemoteCallSingleValueReturn(org.web3j.abi.datatypes.Function function)protected <T> RemoteFunctionCall<T>executeRemoteCallSingleValueReturn(org.web3j.abi.datatypes.Function function, java.lang.Class<T> returnType)protected RemoteFunctionCall<TransactionReceipt>executeRemoteCallTransaction(org.web3j.abi.datatypes.Function function)protected RemoteFunctionCall<TransactionReceipt>executeRemoteCallTransaction(org.web3j.abi.datatypes.Function function, java.math.BigInteger weiValue)protected TransactionReceiptexecuteTransaction(org.web3j.abi.datatypes.Function function)protected org.web3j.abi.EventValuesextractEventParameters(org.web3j.abi.datatypes.Event event, Log log)protected java.util.List<org.web3j.abi.EventValues>extractEventParameters(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt)protected Contract.EventValuesWithLogextractEventParametersWithLog(org.web3j.abi.datatypes.Event event, Log log)protected java.util.List<Contract.EventValuesWithLog>extractEventParametersWithLog(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt)java.lang.StringgetContractAddress()java.lang.StringgetContractBinary()java.lang.StringgetDeployedAddress(java.lang.String networkId)java.math.BigIntegergetGasPrice()Deprecated.use ContractGasProviderprotected java.lang.StringgetStaticDeployedAddress(java.lang.String networkId)Subclasses should implement this method to return pre-existing addresses for deployed contracts.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.booleanisValid()Check that the contract deployed at the address associated with this smart contract wrapper is in fact the contract you believe it is.protected java.lang.StringresolveContractAddress(java.lang.String contractAddress)voidsetContractAddress(java.lang.String contractAddress)voidsetDefaultBlockParameter(DefaultBlockParameter defaultBlockParameter)Sets the default block parameter.voidsetDeployedAddress(java.lang.String networkId, java.lang.String address)voidsetGasPrice(java.math.BigInteger newPrice)Deprecated.use ContractGasProvidervoidsetGasProvider(ContractGasProvider gasProvider)voidsetTransactionReceipt(TransactionReceipt transactionReceipt)static org.web3j.abi.EventValuesstaticExtractEventParameters(org.web3j.abi.datatypes.Event event, Log log)protected static Contract.EventValuesWithLogstaticExtractEventParametersWithLog(org.web3j.abi.datatypes.Event event, Log log)-
Methods inherited from class org.web3j.tx.ManagedTransaction
call, getSyncThreshold, requestCurrentGasPrice, send, send, sendEIP1559, setSyncThreshold
-
-
-
-
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
-
FUNC_DEPLOY
public static final java.lang.String FUNC_DEPLOY
- See Also:
- Constant Field Values
-
contractBinary
protected final java.lang.String contractBinary
-
contractAddress
protected java.lang.String contractAddress
-
gasProvider
protected ContractGasProvider gasProvider
-
transactionReceipt
protected TransactionReceipt transactionReceipt
-
deployedAddresses
protected java.util.Map<java.lang.String,java.lang.String> deployedAddresses
-
defaultBlockParameter
protected DefaultBlockParameter defaultBlockParameter
-
-
Constructor Detail
-
Contract
protected Contract(java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider)
-
Contract
protected Contract(EnsResolver ensResolver, java.lang.String contractBinary, java.lang.String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider)
-
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()
-
setGasProvider
public void setGasProvider(ContractGasProvider gasProvider)
-
setGasPrice
public void setGasPrice(java.math.BigInteger newPrice)
Deprecated.use ContractGasProviderAllowgasPriceto be set.- Parameters:
newPrice- gas price to use for subsequent transactions
-
getGasPrice
public java.math.BigInteger getGasPrice()
Deprecated.use ContractGasProviderGet the currentgasPricevalue this contract uses when executing transactions.- Returns:
- the gas price set on this contract
-
isValid
public boolean isValid() throws java.io.IOExceptionCheck 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
-
executeTransaction
protected TransactionReceipt executeTransaction(org.web3j.abi.datatypes.Function function) throws java.io.IOException, TransactionException
- Throws:
java.io.IOExceptionTransactionException
-
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)
-
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.RuntimeExceptionTransactionException
-
deploy
protected static <T extends Contract> T deploy(java.lang.Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, java.lang.String binary, java.lang.String encodedConstructor, java.math.BigInteger value) throws java.lang.RuntimeException, TransactionException
- Throws:
java.lang.RuntimeExceptionTransactionException
-
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.RuntimeExceptionTransactionException
-
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.RuntimeExceptionTransactionException
-
deployRemoteCall
public static <T extends Contract> RemoteCall<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 Contract> RemoteCall<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 Contract> RemoteCall<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 Contract> RemoteCall<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 Contract> RemoteCall<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 Contract> RemoteCall<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 Contract> RemoteCall<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)
-
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(java.lang.Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, java.lang.String binary, java.lang.String encodedConstructor)
-
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)
-
extractEventParametersWithLog
protected java.util.List<Contract.EventValuesWithLog> extractEventParametersWithLog(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt)
-
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)
-
-