Package org.web3j.tx
Class Contract
java.lang.Object
org.web3j.tx.ManagedTransaction
org.web3j.tx.Contract
- Direct Known Subclasses:
ENS
,ENSRegistryWithFallbackContract
,PublicResolver
Solidity contract type abstraction for interacting with smart contracts via native Java types.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Adds a log field toEventValues
. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected String
protected final String
protected DefaultBlockParameter
static final String
static final BigInteger
Deprecated....protected ContractGasProvider
protected TransactionReceipt
Fields inherited from class org.web3j.tx.ManagedTransaction
ensResolver, GAS_PRICE, transactionManager, web3j
-
Constructor Summary
ModifierConstructorDescriptionprotected
Contract
(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protected
Contract
(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider gasProvider) protected
Contract
(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protected
Contract
(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) protected
Contract
(String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protected
Contract
(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protected
Contract
(EnsResolver ensResolver, String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected static <S extends org.web3j.abi.datatypes.Type,
T>
List<T>convertToNative
(List<S> arr) protected static <T extends Contract>
Tdeploy
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) Deprecated.protected static <T extends Contract>
Tdeploy
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) protected static <T extends Contract>
Tdeploy
(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) Deprecated.protected static <T extends Contract>
Tdeploy
(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) static <T extends Contract>
RemoteCall<T>deployRemoteCall
(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) protected 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, Class<R> returnType) protected String
executeCallWithoutDecoding
(org.web3j.abi.datatypes.Function function) protected RemoteFunctionCall<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, Class<T> returnType) protected RemoteFunctionCall<TransactionReceipt>
executeRemoteCallTransaction
(org.web3j.abi.datatypes.Function function) protected RemoteFunctionCall<TransactionReceipt>
executeRemoteCallTransaction
(org.web3j.abi.datatypes.Function function, BigInteger weiValue) protected TransactionReceipt
executeTransaction
(org.web3j.abi.datatypes.Function function) protected org.web3j.abi.EventValues
extractEventParameters
(org.web3j.abi.datatypes.Event event, Log log) protected List<org.web3j.abi.EventValues>
extractEventParameters
(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) protected Contract.EventValuesWithLog
extractEventParametersWithLog
(org.web3j.abi.datatypes.Event event, Log log) protected List<Contract.EventValuesWithLog>
extractEventParametersWithLog
(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) final String
getDeployedAddress
(String networkId) Deprecated.use ContractGasProviderprotected String
getStaticDeployedAddress
(String networkId) Subclasses should implement this method to return pre-existing addresses for deployed contracts.If this Contract instance was created at deployment, the TransactionReceipt associated with the initial creation will be provided, e.g.boolean
isValid()
Check that the contract deployed at the address associated with this smart contract wrapper is in fact the contract you believe it is.protected String
resolveContractAddress
(String contractAddress) void
setContractAddress
(String contractAddress) void
setDefaultBlockParameter
(DefaultBlockParameter defaultBlockParameter) Sets the default block parameter.final void
setDeployedAddress
(String networkId, String address) void
setGasPrice
(BigInteger newPrice) Deprecated.use ContractGasProvidervoid
setGasProvider
(ContractGasProvider gasProvider) void
setTransactionReceipt
(TransactionReceipt transactionReceipt) static org.web3j.abi.EventValues
staticExtractEventParameters
(org.web3j.abi.datatypes.Event event, Log log) protected static Contract.EventValuesWithLog
staticExtractEventParametersWithLog
(org.web3j.abi.datatypes.Event event, Log log) protected static List<Contract.EventValuesWithLog>
staticExtractEventParametersWithLog
(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) Methods inherited from class org.web3j.tx.ManagedTransaction
call, getSyncThreshold, requestCurrentGasPrice, send, send, sendEIP1559, sendEIP1559, setSyncThreshold
-
Field Details
-
GAS_LIMIT
Deprecated....- See Also:
-
BIN_NOT_PROVIDED
- See Also:
-
FUNC_DEPLOY
- See Also:
-
contractBinary
-
contractAddress
-
gasProvider
-
transactionReceipt
-
deployedAddresses
-
defaultBlockParameter
-
-
Constructor Details
-
Contract
protected Contract(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) -
Contract
protected Contract(EnsResolver ensResolver, String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) -
Contract
protected Contract(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider gasProvider) -
Contract
@Deprecated protected Contract(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated. -
Contract
@Deprecated protected Contract(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated. -
Contract
@Deprecated protected Contract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated. -
Contract
@Deprecated protected Contract(String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated.
-
-
Method Details
-
setContractAddress
-
getContractAddress
-
setTransactionReceipt
-
getContractBinary
-
setGasProvider
-
setGasPrice
Deprecated.use ContractGasProviderAllowgasPrice
to be set.- Parameters:
newPrice
- gas price to use for subsequent transactions
-
getGasPrice
Deprecated.use ContractGasProviderGet the currentgasPrice
value this contract uses when executing transactions.- Returns:
- the gas price set on this contract
-
isValid
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:
IOException
- if unable to connect to web3j node
-
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
Sets the default block parameter. This use useful if one wants to query historical state of a contract.- Parameters:
defaultBlockParameter
- the default block parameter
-
executeCallWithoutDecoding
protected String executeCallWithoutDecoding(org.web3j.abi.datatypes.Function function) throws IOException - Throws:
IOException
-
executeCallSingleValueReturn
protected <T extends org.web3j.abi.datatypes.Type> T executeCallSingleValueReturn(org.web3j.abi.datatypes.Function function) throws IOException - Throws:
IOException
-
executeCallSingleValueReturn
protected <T extends org.web3j.abi.datatypes.Type,R> R executeCallSingleValueReturn(org.web3j.abi.datatypes.Function function, Class<R> returnType) throws IOException - Throws:
IOException
-
executeCallMultipleValueReturn
protected List<org.web3j.abi.datatypes.Type> executeCallMultipleValueReturn(org.web3j.abi.datatypes.Function function) throws IOException - Throws:
IOException
-
executeTransaction
protected TransactionReceipt executeTransaction(org.web3j.abi.datatypes.Function function) throws IOException, TransactionException - Throws:
IOException
TransactionException
-
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, Class<T> returnType) -
executeRemoteCallMultipleValueReturn
protected RemoteFunctionCall<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, BigInteger weiValue) -
deploy
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException - Throws:
RuntimeException
TransactionException
-
deploy
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException - Throws:
RuntimeException
TransactionException
-
deploy
@Deprecated protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException Deprecated.- Throws:
RuntimeException
TransactionException
-
deploy
@Deprecated protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException Deprecated.- Throws:
RuntimeException
TransactionException
-
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) -
deployRemoteCall
public static <T extends Contract> RemoteCall<T> deployRemoteCall(Class<T> type, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) -
staticExtractEventParameters
public static org.web3j.abi.EventValues staticExtractEventParameters(org.web3j.abi.datatypes.Event event, Log log) -
resolveContractAddress
-
extractEventParameters
protected org.web3j.abi.EventValues extractEventParameters(org.web3j.abi.datatypes.Event event, Log log) -
extractEventParameters
protected 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 List<Contract.EventValuesWithLog> extractEventParametersWithLog(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) -
staticExtractEventParametersWithLog
protected static List<Contract.EventValuesWithLog> staticExtractEventParametersWithLog(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) -
getStaticDeployedAddress
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
-
getDeployedAddress
-
convertToNative
-