Created
March 13, 2020 01:54
-
-
Save w3kim/5a459212451d5a22b9b8fa5280164e5b to your computer and use it in GitHub Desktop.
MyERC20 Java Class Generated by caver-java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import com.klaytn.caver.Caver; | |
import com.klaytn.caver.crypto.KlayCredentials; | |
import com.klaytn.caver.methods.response.KlayLogs; | |
import com.klaytn.caver.methods.response.KlayTransactionReceipt; | |
import com.klaytn.caver.tx.SmartContract; | |
import com.klaytn.caver.tx.manager.TransactionManager; | |
import java.math.BigInteger; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import org.web3j.abi.FunctionEncoder; | |
import org.web3j.abi.TypeReference; | |
import org.web3j.abi.datatypes.Address; | |
import org.web3j.abi.datatypes.Event; | |
import org.web3j.abi.datatypes.Function; | |
import org.web3j.abi.datatypes.Type; | |
import org.web3j.abi.datatypes.Utf8String; | |
import org.web3j.abi.datatypes.generated.Uint256; | |
import org.web3j.abi.datatypes.generated.Uint8; | |
import org.web3j.protocol.core.RemoteCall; | |
import org.web3j.tx.gas.ContractGasProvider; | |
/** | |
* <p>Auto generated smart contract code. | |
* <p><strong>Do not modify!</strong> | |
*/ | |
public class MyERC20 extends SmartContract { | |
private static final String BINARY = "60806040523480156200001157600080fd5b50604051620016303803806200163083398101806040528101908080518201929190602001805182019291906020018051906020019092919050505082600290805190602001906200006592919062000332565b5081600390805190602001906200007e92919062000332565b5080600460006101000a81548160ff021916908360ff160217905550620000c0338260ff16600a0a620186a002620000c9640100000000026401000000009004565b505050620003e1565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141515156200016f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b6200019481600554620002a76401000000000262001189179091906401000000009004565b600581905550620001fb816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054620002a76401000000000262001189179091906401000000009004565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600080828401905083811015151562000328576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200037557805160ff1916838001178555620003a6565b82800160010185558215620003a6579182015b82811115620003a557825182559160200191906001019062000388565b5b509050620003b59190620003b9565b5090565b620003de91905b80821115620003da576000816000905550600101620003c0565b5090565b90565b61123f80620003f16000396000f3006080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100bf578063095ea7b31461014f57806318160ddd146101b457806323b872dd146101df578063313ce56714610264578063395093511461029557806370a08231146102fa57806395d89b4114610351578063a25fb97a146103e1578063a457c2d7146104a8578063a9059cbb1461050d578063dd62ed3e14610572575b600080fd5b3480156100cb57600080fd5b506100d46105e9565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101145780820151818401526020810190506100f9565b50505050905090810190601f1680156101415780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015b57600080fd5b5061019a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061068b565b604051808215151515815260200191505060405180910390f35b3480156101c057600080fd5b506101c96106a2565b6040518082815260200191505060405180910390f35b3480156101eb57600080fd5b5061024a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106ac565b604051808215151515815260200191505060405180910390f35b34801561027057600080fd5b5061027961075d565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102a157600080fd5b506102e0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610774565b604051808215151515815260200191505060405180910390f35b34801561030657600080fd5b5061033b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610819565b6040518082815260200191505060405180910390f35b34801561035d57600080fd5b50610366610861565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103a657808201518184015260208101905061038b565b50505050905090810190601f1680156103d35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103ed57600080fd5b5061042c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610903565b604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390f35b3480156104b457600080fd5b506104f3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a15565b604051808215151515815260200191505060405180910390f35b34801561051957600080fd5b50610558600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aba565b604051808215151515815260200191505060405180910390f35b34801561057e57600080fd5b506105d3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ad1565b6040518082815260200191505060405180910390f35b606060028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106815780601f1061065657610100808354040283529160200191610681565b820191906000526020600020905b81548152906001019060200180831161066457829003601f168201915b5050505050905090565b6000610698338484610b58565b6001905092915050565b6000600554905090565b60006106b9848484610dd9565b610752843361074d85600160008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ff90919063ffffffff16565b610b58565b600190509392505050565b6000600460009054906101000a900460ff16905090565b600061080f338461080a85600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118990919063ffffffff16565b610b58565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108f95780601f106108ce576101008083540402835291602001916108f9565b820191906000526020600020905b8154815290600101906020018083116108dc57829003601f168201915b5050505050905090565b600080600083600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503385600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549250925092509250925092565b6000610ab03384610aab85600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ff90919063ffffffff16565b610b58565b6001905092915050565b6000610ac7338484610dd9565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610c23576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001807f45524332303a20617070726f76652066726f6d20746865207a65726f2061646481526020017f726573730000000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614151515610cee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001807f45524332303a20617070726f766520746f20746865207a65726f20616464726581526020017f737300000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610ea4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001807f45524332303a207472616e736665722066726f6d20746865207a65726f20616481526020017f647265737300000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614151515610f6f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001807f45524332303a207472616e7366657220746f20746865207a65726f206164647281526020017f657373000000000000000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b610fc0816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546110ff90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611053816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461118990919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b60008083831115151561117a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525060200191505060405180910390fd5b82840390508091505092915050565b6000808284019050838110151515611209576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b80915050929150505600a165627a7a72305820be7674873ae59175643bc7c55d6f48438960308a38a7bd5b38db6e015932f1400029"; | |
public static final String FUNC_NAME = "name"; | |
public static final String FUNC_APPROVE = "approve"; | |
public static final String FUNC_TOTALSUPPLY = "totalSupply"; | |
public static final String FUNC_TRANSFERFROM = "transferFrom"; | |
public static final String FUNC_DECIMALS = "decimals"; | |
public static final String FUNC_INCREASEALLOWANCE = "increaseAllowance"; | |
public static final String FUNC_BALANCEOF = "balanceOf"; | |
public static final String FUNC_SYMBOL = "symbol"; | |
public static final String FUNC_APPROVETEST = "approveTest"; | |
public static final String FUNC_DECREASEALLOWANCE = "decreaseAllowance"; | |
public static final String FUNC_TRANSFER = "transfer"; | |
public static final String FUNC_ALLOWANCE = "allowance"; | |
public static final Event TRANSFER_EVENT = new Event("Transfer", | |
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {})); | |
; | |
public static final Event APPROVAL_EVENT = new Event("Approval", | |
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {})); | |
; | |
protected MyERC20(String contractAddress, Caver caver, KlayCredentials credentials, int chainId, ContractGasProvider contractGasProvider) { | |
super(BINARY, contractAddress, caver, credentials, chainId, contractGasProvider); | |
} | |
protected MyERC20(String contractAddress, Caver caver, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { | |
super(BINARY, contractAddress, caver, transactionManager, contractGasProvider); | |
} | |
public RemoteCall<String> name() { | |
final Function function = new Function(FUNC_NAME, | |
Arrays.<Type>asList(), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {})); | |
return executeRemoteCallSingleValueReturn(function, String.class); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> approve(String spender, BigInteger value) { | |
final Function function = new Function( | |
FUNC_APPROVE, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(spender), | |
new org.web3j.abi.datatypes.generated.Uint256(value)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<BigInteger> totalSupply() { | |
final Function function = new Function(FUNC_TOTALSUPPLY, | |
Arrays.<Type>asList(), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | |
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> transferFrom(String sender, String recipient, BigInteger amount) { | |
final Function function = new Function( | |
FUNC_TRANSFERFROM, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(sender), | |
new org.web3j.abi.datatypes.Address(recipient), | |
new org.web3j.abi.datatypes.generated.Uint256(amount)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<BigInteger> decimals() { | |
final Function function = new Function(FUNC_DECIMALS, | |
Arrays.<Type>asList(), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Uint8>() {})); | |
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> increaseAllowance(String spender, BigInteger addedValue) { | |
final Function function = new Function( | |
FUNC_INCREASEALLOWANCE, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(spender), | |
new org.web3j.abi.datatypes.generated.Uint256(addedValue)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<BigInteger> balanceOf(String account) { | |
final Function function = new Function(FUNC_BALANCEOF, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(account)), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | |
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | |
} | |
public RemoteCall<String> symbol() { | |
final Function function = new Function(FUNC_SYMBOL, | |
Arrays.<Type>asList(), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {})); | |
return executeRemoteCallSingleValueReturn(function, String.class); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> approveTest(String spender, BigInteger value) { | |
final Function function = new Function( | |
FUNC_APPROVETEST, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(spender), | |
new org.web3j.abi.datatypes.generated.Uint256(value)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> decreaseAllowance(String spender, BigInteger subtractedValue) { | |
final Function function = new Function( | |
FUNC_DECREASEALLOWANCE, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(spender), | |
new org.web3j.abi.datatypes.generated.Uint256(subtractedValue)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<KlayTransactionReceipt.TransactionReceipt> transfer(String recipient, BigInteger amount) { | |
final Function function = new Function( | |
FUNC_TRANSFER, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(recipient), | |
new org.web3j.abi.datatypes.generated.Uint256(amount)), | |
Collections.<TypeReference<?>>emptyList()); | |
return executeRemoteCallTransaction(function); | |
} | |
public RemoteCall<BigInteger> allowance(String owner, String spender) { | |
final Function function = new Function(FUNC_ALLOWANCE, | |
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(owner), | |
new org.web3j.abi.datatypes.Address(spender)), | |
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | |
return executeRemoteCallSingleValueReturn(function, BigInteger.class); | |
} | |
public List<TransferEventResponse> getTransferEvents(KlayTransactionReceipt.TransactionReceipt transactionReceipt) { | |
List<SmartContract.EventValuesWithLog> valueList = extractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt); | |
ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size()); | |
for (SmartContract.EventValuesWithLog eventValues : valueList) { | |
TransferEventResponse typedResponse = new TransferEventResponse(); | |
typedResponse.log = eventValues.getLog(); | |
typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue(); | |
typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue(); | |
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); | |
responses.add(typedResponse); | |
} | |
return responses; | |
} | |
public List<ApprovalEventResponse> getApprovalEvents(KlayTransactionReceipt.TransactionReceipt transactionReceipt) { | |
List<SmartContract.EventValuesWithLog> valueList = extractEventParametersWithLog(APPROVAL_EVENT, transactionReceipt); | |
ArrayList<ApprovalEventResponse> responses = new ArrayList<ApprovalEventResponse>(valueList.size()); | |
for (SmartContract.EventValuesWithLog eventValues : valueList) { | |
ApprovalEventResponse typedResponse = new ApprovalEventResponse(); | |
typedResponse.log = eventValues.getLog(); | |
typedResponse.owner = (String) eventValues.getIndexedValues().get(0).getValue(); | |
typedResponse.spender = (String) eventValues.getIndexedValues().get(1).getValue(); | |
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); | |
responses.add(typedResponse); | |
} | |
return responses; | |
} | |
public static MyERC20 load(String contractAddress, Caver caver, KlayCredentials credentials, int chainId, ContractGasProvider contractGasProvider) { | |
return new MyERC20(contractAddress, caver, credentials, chainId, contractGasProvider); | |
} | |
public static MyERC20 load(String contractAddress, Caver caver, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { | |
return new MyERC20(contractAddress, caver, transactionManager, contractGasProvider); | |
} | |
public static RemoteCall<MyERC20> deploy(Caver caver, KlayCredentials credentials, int chainId, ContractGasProvider contractGasProvider, String name, String symbol, BigInteger decimals) { | |
String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(name), | |
new org.web3j.abi.datatypes.Utf8String(symbol), | |
new org.web3j.abi.datatypes.generated.Uint8(decimals))); | |
return deployRemoteCall(MyERC20.class, caver, credentials, chainId, contractGasProvider, BINARY, encodedConstructor); | |
} | |
public static RemoteCall<MyERC20> deploy(Caver caver, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String name, String symbol, BigInteger decimals) { | |
String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(name), | |
new org.web3j.abi.datatypes.Utf8String(symbol), | |
new org.web3j.abi.datatypes.generated.Uint8(decimals))); | |
return deployRemoteCall(MyERC20.class, caver, transactionManager, contractGasProvider, BINARY, encodedConstructor); | |
} | |
public static class TransferEventResponse { | |
public KlayLogs.Log log; | |
public String from; | |
public String to; | |
public BigInteger value; | |
} | |
public static class ApprovalEventResponse { | |
public KlayLogs.Log log; | |
public String owner; | |
public String spender; | |
public BigInteger value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment