Class Contract
- java.lang.Object
-
- com.klaytn.caver.contract.Contract
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Type>
call(CallObject callObject, java.lang.String methodName, java.lang.Object... methodArguments)
Execute smart contract method in the EVM without sending any transaction.java.util.List<Type>
call(java.lang.String methodName, java.lang.Object... methodArguments)
Execute smart contract method in the EVM without sending any transaction.java.util.List<Type>
callWithSolidityType(CallObject callObject, java.lang.String methodName, Type... methodArguments)
Execute smart contract method in the EVM without sending any transaction.java.util.List<Type>
callWithSolidityType(java.lang.String methodName, Type... methodArguments)
Execute smart contract method in the EVM without sending any transaction.static Contract
create(Caver caver, java.lang.String abi)
Creates a Contract instance.static Contract
create(Caver caver, java.lang.String abi, java.lang.String contractAddress)
Creates a Contract instance.java.util.List<Type>
decodeFunctionCall(java.lang.String encodedString)
Decodes a function call data that composed of function selector and encoded input argument.Contract
deploy(ContractDeployParams deployParam, SendOptions sendOptions)
Deploy a contract.Contract
deploy(ContractDeployParams deployParam, SendOptions sendOptions, TransactionReceiptProcessor processor)
Deploy a contractContract
deploy(SendOptions sendOptions, TransactionReceiptProcessor receiptProcessor, java.lang.String contractBinaryData, java.lang.Object... constructorParams)
Deploy a contractContract
deploy(SendOptions sendOptions, java.lang.String contractBinaryData, java.lang.Object... constructorParams)
Deploy a contractjava.lang.String
encodeABI(java.lang.String methodName, java.lang.Object... methodArguments)
Encodes the ABI for the method in Contract.java.lang.String
encodeABIWithSolidityType(java.lang.String methodName, Type... methodArguments)
Encodes the ABI for the method in Contract with Solidity type wrapper reference.java.lang.String
estimateGas(CallObject callObject, java.lang.String methodName, java.lang.Object... methodArguments)
Estimate the gas to execute the contract's method.java.lang.String
estimateGasWithSolidityType(CallObject callObject, java.lang.String methodName, Type... methodArguments)
Estimate the gas to execute the contract's method with Solidity type wrapper reference.ContractMethod
findContractMethodBySignature(java.lang.String functionSignature)
Find a ContractMethod instance that has the function signature same as passed as a parameter.java.lang.String
getAbi()
Getter function for contract's abi.Caver
getCaver()
Getter function for caver.ContractMethod
getConstructor()
Getter function for Contract's constructor function info.java.lang.String
getContractAddress()
Getter function for contract address.SendOptions
getDefaultSendOptions()
Getter function for DefaultSendOptionsContractEvent
getEvent(java.lang.String eventName)
Returns the ContractEvent instance corresponding to the event name.java.util.Map<java.lang.String,ContractEvent>
getEvents()
Getter function for events.ContractMethod
getMethod(java.lang.String methodName)
Returns the ContractMethod instance corresponding to the method name.java.util.Map<java.lang.String,ContractMethod>
getMethods()
Getter function for methods.KlayLogs
getPastEvent(java.lang.String eventName, KlayLogFilter filterOption)
Get past events for this contract.IWallet
getWallet()
Getter function for walletio.reactivex.disposables.Disposable
once(java.lang.String eventName, EventFilterOptions paramsOption, io.reactivex.functions.Consumer<LogsNotification> callback)
Subscribes to an event and unsubscribes immediately after the first event or error.TransactionReceipt.TransactionReceiptData
send(SendOptions options, TransactionReceiptProcessor receiptProcessor, java.lang.String methodName, java.lang.Object... methodArguments)
Send a transaction to smart contract and execute its method.TransactionReceipt.TransactionReceiptData
send(SendOptions options, java.lang.String methodName, java.lang.Object... methodArguments)
Send a transaction to smart contract and execute its method.TransactionReceipt.TransactionReceiptData
send(java.lang.String methodName, java.lang.Object... methodArguments)
Send a transaction to smart contract and execute its method.TransactionReceipt.TransactionReceiptData
sendWithSolidityType(SendOptions options, TransactionReceiptProcessor receiptProcessor, java.lang.String methodName, Type... methodArguments)
Send a transaction to smart contract and execute its method using solidity type wrapper class.TransactionReceipt.TransactionReceiptData
sendWithSolidityType(SendOptions options, java.lang.String methodName, Type... methodArguments)
Send a transaction to smart contract and execute its method using solidity type wrapper class.TransactionReceipt.TransactionReceiptData
sendWithSolidityType(java.lang.String methodName, Type... methodArguments)
Send a transaction to smart contract and execute its method using solidity type wrapper class.void
setDefaultSendOptions(SendOptions defaultSendOptions)
Setter function for defaultSendOptionvoid
setWallet(IWallet wallet)
Setter function for walletAbstractTransaction
sign(SendOptions sendOptions, java.lang.String methodName, java.lang.Object... methodArguments)
Create and sign a transaction with the input data generated by the passed argument.AbstractTransaction
sign(java.lang.String methodName, java.lang.Object... methodArguments)
Create and sign a transaction with the input data generated by the passed argument.AbstractFeeDelegatedTransaction
signAsFeePayer(SendOptions sendOptions, java.lang.String methodName, java.lang.Object... methodArguments)
/** Create and sign a transaction as a fee payer with the input data generated by the passed argument.AbstractTransaction
signAsFeePayer(java.lang.String methodName, java.lang.Object... methodArguments)
Create and sign a transaction as a fee payer with the input data generated by the passed argument.AbstractFeeDelegatedTransaction
signAsFeePayerWithSolidityType(SendOptions sendOptions, java.lang.String methodName, Type... methodArguments)
Create and sign a transaction as a fee payer with the input data generated by the passed argument that wrapped by solidity type class.AbstractFeeDelegatedTransaction
signAsFeePayerWithSolidityType(java.lang.String methodName, Type... methodArguments)
Create and sign a transaction as a fee payer with the input data generated by the passed argument that wrapped by solidity type class.AbstractTransaction
signWithSolidityType(SendOptions sendOptions, java.lang.String methodName, Type... methodArguments)
Create and sign a transaction with the input data generated by the passed argument that wrapped by solidity type class.AbstractTransaction
signWithSolidityType(java.lang.String methodName, Type... methodArguments)
Create and sign a transaction with the input data generated by the passed argument that wrapped by solidity type class.io.reactivex.disposables.Disposable
subscribe(java.lang.String eventName, EventFilterOptions paramsOption, io.reactivex.functions.Consumer<LogsNotification> callback)
Subscribes to an event.
-
-
-
Constructor Detail
-
Contract
public Contract(Caver caver, java.lang.String abi) throws java.io.IOException
Creates a Contract instance.- Parameters:
caver
- A Caver instance.abi
- A contract's ABI(Application Binary interface) json string.- Throws:
java.io.IOException
-
Contract
public Contract(Caver caver, java.lang.String abi, java.lang.String contractAddress) throws java.io.IOException
Creates a Contract instance.- Parameters:
caver
- A Caver instanceabi
- A contract's ABI(Application Binary Interface) json string.contractAddress
- An address string of contract deployed on Klaytn.- Throws:
java.io.IOException
-
-
Method Detail
-
create
public static Contract create(Caver caver, java.lang.String abi) throws java.io.IOException
Creates a Contract instance.- Parameters:
caver
- A Caver instance.abi
- A contract's ABI(Application Binary interface) json string.- Returns:
- Contract
- Throws:
java.io.IOException
-
create
public static Contract create(Caver caver, java.lang.String abi, java.lang.String contractAddress) throws java.io.IOException
Creates a Contract instance.- Parameters:
caver
- A Caver instance.abi
- A contract's ABI(Application Binary interface) json string.contractAddress
- An address string of contract deployed on Klaytn.- Returns:
- Contract
- Throws:
java.io.IOException
-
deploy
public Contract deploy(SendOptions sendOptions, java.lang.String contractBinaryData, java.lang.Object... constructorParams) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Deploy a contract- Parameters:
sendOptions
- A SendOption instance.contractBinaryData
- A smart contract binary data.constructorParams
- The smart contract constructor parameters.- Returns:
- Contract
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.lang.NoSuchMethodException
java.io.IOException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
deploy
public Contract deploy(SendOptions sendOptions, TransactionReceiptProcessor receiptProcessor, java.lang.String contractBinaryData, java.lang.Object... constructorParams) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Deploy a contract- Parameters:
sendOptions
- A SendOption instancereceiptProcessor
- A TransactionReceiptProcessor instance.contractBinaryData
- A smart contract binary data.constructorParams
- The smart contract constructor parameters.- Returns:
- Contract
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.lang.NoSuchMethodException
java.io.IOException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
deploy
public Contract deploy(ContractDeployParams deployParam, SendOptions sendOptions) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Deploy a contract. It sets TransactionReceiptProcessor to PollingTransactionReceiptProcessor instance.- Parameters:
deployParam
- A DeployParam instance.sendOptions
- A SendOption instance.- Returns:
- Contract
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
deploy
public Contract deploy(ContractDeployParams deployParam, SendOptions sendOptions, TransactionReceiptProcessor processor) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Deploy a contract- Parameters:
deployParam
- A DeployParam instance.sendOptions
- A SendOption instance.processor
- A TransactionReceiptProcessor instance.- Returns:
- Contract
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
once
public io.reactivex.disposables.Disposable once(java.lang.String eventName, EventFilterOptions paramsOption, io.reactivex.functions.Consumer<LogsNotification> callback) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
Subscribes to an event and unsubscribes immediately after the first event or error.You can filter event through setting filterOptions or topics field in EventFilterOptions.
Example :
Contract contract = caver.contract.create(ABI, contractAddress); EventFilterOptions options = new EventFilterOptions(); options.setFilterOptions(Arrays.asList(new EventFilterOptions.IndexedParameter("from", "0x{address}"))); //or options.setTopics(Arrays.asList("topic0", "topic1")); Disposable disposable = contract.once("Transfer", options, (data) -> {});
- Parameters:
eventName
- The name of the event in the contract.paramsOption
- The filter events by indexed parameters.callback
- The callback function that handled to returned data.- Returns:
- Disposable instance that able to unsubscribe.
- Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
subscribe
public io.reactivex.disposables.Disposable subscribe(java.lang.String eventName, EventFilterOptions paramsOption, io.reactivex.functions.Consumer<LogsNotification> callback) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
Subscribes to an event.You can filter event through setting filterOptions or topics field in EventFilterOptions.
Example :
Contract contract = caver.contract.create(ABI, contractAddress); EventFilterOptions options = new EventFilterOptions(); options.setFilterOptions(Arrays.asList(new EventFilterOptions.IndexedParameter("from", "0x{address}"))); //or options.setTopics(Arrays.asList("topic0", "topic1")); Disposable disposable = contract.subscribe("Transfer", options, (data) -> {}); // You can unsubscribe the event like below disposable.dispose();
- Parameters:
eventName
- The name of the event in the contract, or "allEvents" to get all events.paramsOption
- The filter events by indexed parameters.callback
- The callback function that handled to returned data.- Returns:
- Disposable instance that able to unsubscribe.
- Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
getPastEvent
public KlayLogs getPastEvent(java.lang.String eventName, KlayLogFilter filterOption) throws java.io.IOException
Get past events for this contract.- Parameters:
eventName
- The name of the event in the contract.filterOption
- The KlayLogFilter instance to filter event.- Returns:
- KlayLogs
- Throws:
java.io.IOException
-
call
public java.util.List<Type> call(java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
Execute smart contract method in the EVM without sending any transaction.- Parameters:
methodName
- The smart contract method name to execute.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- List
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
call
public java.util.List<Type> call(CallObject callObject, java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
Execute smart contract method in the EVM without sending any transaction. When creating CallObject, it need not to fill 'data', 'to' fields. The 'data', 'to' fields automatically filled in call() method.- Parameters:
callObject
- A CallObject instance to 'call' smart contract method.methodName
- The smart contract method name to execute.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- List
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
callWithSolidityType
public java.util.List<Type> callWithSolidityType(java.lang.String methodName, Type... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException
Execute smart contract method in the EVM without sending any transaction. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
methodName
- The smart contract method name to execute.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- List
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
callWithSolidityType
public java.util.List<Type> callWithSolidityType(CallObject callObject, java.lang.String methodName, Type... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException
Execute smart contract method in the EVM without sending any transaction. It is recommended to use this function when you want to execute one of the functions with the same number of parameters. When creating CallObject, it need not to fill 'data', 'to' fields. The 'data', 'to' fields automatically filled in call() method.- Parameters:
callObject
- A CallObject instance to 'call' smart contract method.methodName
- The smart contract method name to execute.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- List
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
send
public TransactionReceipt.TransactionReceiptData send(java.lang.String methodName, java.lang.Object... methodArguments) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Send a transaction to smart contract and execute its method. It is used defaultSendOption field to sendOptions. It sets TransactionReceiptProcessor to PollingTransactionReceiptProcessor.- Parameters:
methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
send
public TransactionReceipt.TransactionReceiptData send(SendOptions options, java.lang.String methodName, java.lang.Object... methodArguments) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Send a transaction to smart contract and execute its method. It sets TransactionReceiptProcessor to PollingTransactionReceiptProcessor.- Parameters:
options
- An option to execute smart contract method.methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
send
public TransactionReceipt.TransactionReceiptData send(SendOptions options, TransactionReceiptProcessor receiptProcessor, java.lang.String methodName, java.lang.Object... methodArguments) throws org.web3j.protocol.exceptions.TransactionException, java.io.IOException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Send a transaction to smart contract and execute its method.- Parameters:
options
- An option to execute smart contract method.receiptProcessor
- A TransactionReceiptProcessor to get receipt.methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
org.web3j.protocol.exceptions.TransactionException
java.io.IOException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
sendWithSolidityType
public TransactionReceipt.TransactionReceiptData sendWithSolidityType(java.lang.String methodName, Type... methodArguments) throws java.io.IOException, org.web3j.protocol.exceptions.TransactionException
Send a transaction to smart contract and execute its method using solidity type wrapper class. It is used defaultSendOption field to sendOptions It sets TransactionReceiptProcessor to PollingTransactionReceiptProcessor. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
java.io.IOException
org.web3j.protocol.exceptions.TransactionException
-
sendWithSolidityType
public TransactionReceipt.TransactionReceiptData sendWithSolidityType(SendOptions options, java.lang.String methodName, Type... methodArguments) throws java.io.IOException, org.web3j.protocol.exceptions.TransactionException
Send a transaction to smart contract and execute its method using solidity type wrapper class. It sets TransactionReceiptProcessor to PollingTransactionReceiptProcessor. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
options
- An option to execute smart contract method.methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
java.io.IOException
org.web3j.protocol.exceptions.TransactionException
-
sendWithSolidityType
public TransactionReceipt.TransactionReceiptData sendWithSolidityType(SendOptions options, TransactionReceiptProcessor receiptProcessor, java.lang.String methodName, Type... methodArguments) throws java.io.IOException, org.web3j.protocol.exceptions.TransactionException
Send a transaction to smart contract and execute its method using solidity type wrapper class. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
options
- An option to execute smart contract method.receiptProcessor
- A TransactionReceiptProcessor to get receipt.methodName
- The smart contract method name to executemethodArguments
- The arguments that need to execute smart contract method.- Returns:
- TransactionReceiptData
- Throws:
java.io.IOException
org.web3j.protocol.exceptions.TransactionException
-
sign
public AbstractTransaction sign(java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException
Create and sign a transaction with the input data generated by the passed argument.If the method name is a "constructor", it creates a transaction related to SmartContractDeploy and sign it. The arguments parsed as follow. - arguments[0] : Smart contract's bytecode. - others : The constructor arguments to deploy smart contract.
Caver caver = new Caver(Caver.DEFAULT_URL); String abi = "abi"; String bytecode = "Contract bytecode"; SendOptions sendOptions = new SendOptions(); sendOptions.setFrom("0x{from}"); sendOptions.setGas(BigInteger.valueOf(100000000)); Contract contract = caver.contract.create(abi); contract.setDefaultSendOptions(sendOptions); contract.sign("constructor", bytecode, constructor_param1, constructor_param2...);
It is used defaultSendOption field to sendOptions.- Parameters:
methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException
-
sign
public AbstractTransaction sign(SendOptions sendOptions, java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException
Create and sign a transaction with the input data generated by the passed argument.It creates a transaction related to SmartContractDeploy or SmartContractExecution to deploy or execute smart contract method.
If the method name is a "constructor", it creates a transaction related to SmartContractDeploy and sign it. The arguments parsed as follow. - arguments[0] : Smart contract's bytecode. - others : The constructor arguments to deploy smart contract.
Caver caver = new Caver(Caver.DEFAULT_URL); String abi = "abi"; String bytecode = "Contract bytecode"; Contract contract = caver.contract.create(abi); SendOptions sendOptions = new SendOptions(); sendOptions.setFrom("0x{from}"); sendOptions.setGas(BigInteger.valueOf(100000000)); contract.sign(sendOptions, "constructor", bytecode, constructor_param1, constructor_param2...);
- Parameters:
sendOptions
- An option to deploy or execute smart contract method.methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
signWithSolidityType
public AbstractTransaction signWithSolidityType(java.lang.String methodName, Type... methodArguments) throws java.io.IOException
Create and sign a transaction with the input data generated by the passed argument that wrapped by solidity type class.It creates a transaction related to SmartContractExecution to execute smart contract method.
It is recommended to use this function when you want to execute one of the functions with the same number of parameters.
It is used defaultSendOption field to sendOptions.
- Parameters:
methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
signWithSolidityType
public AbstractTransaction signWithSolidityType(SendOptions sendOptions, java.lang.String methodName, Type... methodArguments) throws java.io.IOException
Create and sign a transaction with the input data generated by the passed argument that wrapped by solidity type class.It creates a transaction related to SmartContractExecution to execute smart contract method.
It is recommended to use this function when you want to execute one of the functions with the same number of parameters.
- Parameters:
sendOptions
- An option to execute smart contract method.methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
signAsFeePayer
public AbstractTransaction signAsFeePayer(java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException
Create and sign a transaction as a fee payer with the input data generated by the passed argument.If the method name is a "constructor", it creates a transaction related to FeeDelegatedSmartContractDeploy and sign it. The arguments parsed as follow. - arguments[0] : Smart contract's bytecode. - others : The constructor arguments to deploy smart contract.
Caver caver = new Caver(Caver.DEFAULT_URL); String abi = "Contract ABI data"; String bytecode = "Contract bytecode"; SendOptions sendOptions = new SendOptions(); sendOptions.setFrom("0x{from}"); sendOptions.setGas(BigInteger.valueOf(100000000)); sendOptions.setFeeDelegation(true); sendOptions.setFeePayer("0x{feePayer}"); Contract contract = caver.contract.create(abi); contract.setDefaultSendOptions(sendOptions); contract.signAsFeePayer("constructor", bytecode, constructor_param1, constructor_param2...);
- Parameters:
methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
signAsFeePayer
public AbstractFeeDelegatedTransaction signAsFeePayer(SendOptions sendOptions, java.lang.String methodName, java.lang.Object... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException
/** Create and sign a transaction as a fee payer with the input data generated by the passed argument.If the method name is a "constructor", it creates a transaction related to FeeDelegatedSmartContractDeploy and sign it. The arguments parsed as follow. - arguments[0] : Smart contract's bytecode. - others : The constructor arguments to deploy smart contract.
Caver caver = new Caver(Caver.DEFAULT_URL); String abi = "Contract ABI data"; String bytecode = "Contract bytecode"; SendOptions sendOptions = new SendOptions(); sendOptions.setFrom("0x{from}"); sendOptions.setGas(BigInteger.valueOf(100000000)); sendOptions.setFeeDelegation(true); sendOptions.setFeePayer("0x{feePayer}"); Contract contract = caver.contract.create(abi); contract.signAsFeePayer(sendOptions, "constructor", bytecode, constructor_param1, constructor_param2...);
- Parameters:
sendOptions
- An option to execute smart contract method.methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- The list of arguments to execute or deploy a smart contract.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
signAsFeePayerWithSolidityType
public AbstractFeeDelegatedTransaction signAsFeePayerWithSolidityType(java.lang.String methodName, Type... methodArguments) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.IllegalAccessException
Create and sign a transaction as a fee payer with the input data generated by the passed argument that wrapped by solidity type class.It creates a transaction related to FeeDelegatedSmartContractExecution to execute smart contract method.
It is used defaultSendOption field to sendOptions.
It is recommended to use this function when you want to execute one of the functions with the same number of parameters.
- Parameters:
methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- A List of parameter that wrapped by solidity type class.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
signAsFeePayerWithSolidityType
public AbstractFeeDelegatedTransaction signAsFeePayerWithSolidityType(SendOptions sendOptions, java.lang.String methodName, Type... methodArguments) throws java.io.IOException
Create and sign a transaction as a fee payer with the input data generated by the passed argument that wrapped by solidity type class.It creates a transaction related to FeeDelegatedSmartContractExecution to execute smart contract method.
It is recommended to use this function when you want to execute one of the functions with the same number of parameters.
- Parameters:
sendOptions
- An option to execute smart contract method.methodName
- The smart contract's method name to create a transaction and sign it.methodArguments
- A List of parameter that wrapped by solidity type class.- Returns:
- AbstractTransaction
- Throws:
java.io.IOException
-
encodeABI
public java.lang.String encodeABI(java.lang.String methodName, java.lang.Object... methodArguments) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException, java.lang.IllegalAccessException
Encodes the ABI for the method in Contract. The resulting hex string is 32-bit function signature hash plus the passed parameters in Solidity tightly packed format.- Parameters:
methodName
- The smart contract method name to encode.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- String
- Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
java.lang.IllegalAccessException
-
encodeABIWithSolidityType
public java.lang.String encodeABIWithSolidityType(java.lang.String methodName, Type... methodArguments)
Encodes the ABI for the method in Contract with Solidity type wrapper reference. The resulting hex string is 32-bit function signature hash plus the passed parameters in Solidity tightly packed format. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
methodName
- The smart contract method name to encode.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- String
-
estimateGas
public java.lang.String estimateGas(CallObject callObject, java.lang.String methodName, java.lang.Object... methodArguments) throws java.lang.NoSuchMethodException, java.io.IOException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundException
Estimate the gas to execute the contract's method.- Parameters:
callObject
- An option to execute smart contract method.methodName
- The smart contract method name.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- String
- Throws:
java.lang.NoSuchMethodException
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
-
estimateGasWithSolidityType
public java.lang.String estimateGasWithSolidityType(CallObject callObject, java.lang.String methodName, Type... methodArguments) throws java.io.IOException
Estimate the gas to execute the contract's method with Solidity type wrapper reference. It is recommended to use this function when you want to execute one of the functions with the same number of parameters.- Parameters:
callObject
- An option to execute smart contract method.methodName
- The smart contract method name.methodArguments
- The arguments that need to execute smart contract method.- Returns:
- String
- Throws:
java.io.IOException
-
decodeFunctionCall
public java.util.List<Type> decodeFunctionCall(java.lang.String encodedString) throws java.lang.ClassNotFoundException
Decodes a function call data that composed of function selector and encoded input argument.Example :
String contractABI = "....."; Contract contract = caver.contract.create(contractABI); List<Type> decoded = contract.decodeFunctionCall("0x{encoded function call data}");
- Parameters:
encodedString
- The encoded function call data string.- Returns:
- List<Type>
- Throws:
java.lang.ClassNotFoundException
-
findContractMethodBySignature
public ContractMethod findContractMethodBySignature(java.lang.String functionSignature)
Find a ContractMethod instance that has the function signature same as passed as a parameter.- Parameters:
functionSignature
- The function signature to find a ContractMethod instance.- Returns:
- ContractMethod
-
getMethod
public ContractMethod getMethod(java.lang.String methodName)
Returns the ContractMethod instance corresponding to the method name.- Parameters:
methodName
- The method name.- Returns:
- ContractMethod
-
getEvent
public ContractEvent getEvent(java.lang.String eventName)
Returns the ContractEvent instance corresponding to the event name.- Parameters:
eventName
- The event name.- Returns:
- ContractEvent
-
getCaver
public Caver getCaver()
Getter function for caver.- Returns:
- Caver
-
getAbi
public java.lang.String getAbi()
Getter function for contract's abi.- Returns:
- String
-
getContractAddress
public java.lang.String getContractAddress()
Getter function for contract address.- Returns:
- String
-
getMethods
public java.util.Map<java.lang.String,ContractMethod> getMethods()
Getter function for methods.- Returns:
- Map
-
getEvents
public java.util.Map<java.lang.String,ContractEvent> getEvents()
Getter function for events.- Returns:
- Map
-
getConstructor
public ContractMethod getConstructor()
Getter function for Contract's constructor function info.- Returns:
- ContractMethod.
-
getDefaultSendOptions
public SendOptions getDefaultSendOptions()
Getter function for DefaultSendOptions- Returns:
- SendOptions
-
getWallet
public IWallet getWallet()
Getter function for wallet- Returns:
- IWallet
-
setWallet
public void setWallet(IWallet wallet)
Setter function for wallet- Parameters:
wallet
- The class instance implemented IWallet to sign transaction.
-
setDefaultSendOptions
public void setDefaultSendOptions(SendOptions defaultSendOptions)
Setter function for defaultSendOption- Parameters:
defaultSendOptions
- The sendOptions to set DefaultSendOptions field.
-
-