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
Nested ClassesModifier and TypeClassDescriptionstatic classAdds a log field toEventValues. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected Stringprotected final Stringprotected DefaultBlockParameterstatic final Stringstatic final BigIntegerDeprecated....protected ContractGasProviderprotected TransactionReceiptFields inherited from class org.web3j.tx.ManagedTransaction
ensResolver, GAS_PRICE, transactionManager, web3j -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedContract(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protectedContract(String contractBinary, String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, ContractGasProvider gasProvider) protectedContract(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protectedContract(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) protectedContract(String contractAddress, Web3j web3j, org.web3j.crypto.Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protectedContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) Deprecated.protectedContract(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 StringexecuteCallWithoutDecoding(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 TransactionReceiptexecuteTransaction(org.web3j.abi.datatypes.Function function) protected org.web3j.abi.EventValuesextractEventParameters(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.EventValuesWithLogextractEventParametersWithLog(org.web3j.abi.datatypes.Event event, Log log) protected List<Contract.EventValuesWithLog>extractEventParametersWithLog(org.web3j.abi.datatypes.Event event, TransactionReceipt transactionReceipt) final StringgetDeployedAddress(String networkId) Deprecated.use ContractGasProviderprotected StringgetStaticDeployedAddress(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.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 StringresolveContractAddress(String contractAddress) voidsetContractAddress(String contractAddress) voidsetDefaultBlockParameter(DefaultBlockParameter defaultBlockParameter) Sets the default block parameter.final voidsetDeployedAddress(String networkId, String address) voidsetGasPrice(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) 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 ContractGasProviderAllowgasPriceto be set.- Parameters:
newPrice- gas price to use for subsequent transactions
-
getGasPrice
Deprecated.use ContractGasProviderGet the currentgasPricevalue 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:
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, 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:
RuntimeExceptionTransactionException
-
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:
RuntimeExceptionTransactionException
-
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:
RuntimeExceptionTransactionException
-
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:
RuntimeExceptionTransactionException
-
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
-