public class Jthereum
extends Object
The main method to compile and deploy contracts is... compileAndDeploy().
There are also methods for creating Proxy Objects, which are used to call contract methods on the blockchain.
There are also a few convenience methods for doing blockchain related tasks.
Each method comes with a few variants that take different numbers of arguments for your convenience.
There is an ArgumentManager which attempts to figure out what values should be used for missing arguments.
You can view a dump of chosen argment values, along with the source of the argument, by setting a property in 'jthereum.config' (in the instllation directory), or 'jtherem.properties' in your project directory to:
DUMP_ARGUMENT_DETAILS_TO_CONSOLE=true
The primary public methods of this class are:
compile() -- Compile your Contract to check for errors compileAndDeploy() -- Compile your contract and deploy to the blockchain createProxy() -- Create a proxy object to access a contract
The misc helper methods include:
getBalance() -- Get the ETH balance of an account getMyAddress() -- Get the account address used to send transactions from getNextNonce() -- get the nonce value for an account sendEth() -- Send some ETH sendAllEth() -- Send all ETH from an account you control weiAmountToString() -- Format an ETH amount as a string suitable for printing getJthereumProperties() -- Get the current Properties object.
Note that if your contract class contains a main() function, then you can call both compileAndDeploy(), and/or createProxy() with *zero* arguments, which makes things super-simple.
Modifier and Type | Field and Description |
---|---|
static java.math.BigInteger |
ETHER
Constant value representing one Ether (10^18 Wei, 1,000 Finney)
|
static java.math.BigInteger |
FINNEY
Constant value representing one Finney (10^15 Wei, 1,000 Szabo)
|
static java.math.BigInteger |
GWEI
Constant value representing one Wei
|
static java.math.BigInteger |
SZABO
Constant value representing one GWei (10^9 Wei)
|
static java.math.BigInteger |
WEI
Constant value representing one Wei
|
Modifier and Type | Method and Description |
---|---|
static String |
compile()
Compiles (translates) the Java class into Solidity code suitable to be compiled and deployed to the blockchain, and attempts to compile the generated code.
|
static String |
compile(Class _class)
Compiles (translates) the Java class into Solidity code suitable to be compiled and deployed to the blockchain, and attempts to compile the generated code.
|
static String |
compileAndDeploy()
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(boolean verifySource)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(Class _class)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(Class _class,
boolean verifySource)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(Class _class,
String blockchainName)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(Class _class,
String blockchainName,
boolean verifySource)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(String blockchainName)
Compiles the given Java class, and deploys it to the blockchain.
|
static String |
compileAndDeploy(String blockchainName,
boolean verifySource)
Compiles the given Java class, and deploys it to the blockchain.
|
static Object |
createProxy()
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static <T> T |
createProxy(Class<T> _class)
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static <T> T |
createProxy(Class<T> _class,
String blockchainName)
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static <T> T |
createProxy(Class<T> _class,
String blockchainName,
String contractAddress)
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static Object |
createProxy(String blockchainName)
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static Object |
createProxy(String blockchainName,
String contractAddress)
Creates a Proxy Object that will delegate method calls to a contract deployed on the blockchain.
|
static boolean |
doesAddressContainContract(String blockchainName,
String address)
Returns true iff the address on the specified blockchain contains a contract.
|
static com.u7.jthereum.internal.EtherscanSourceCodeDetails |
generateJavaProxyFromEtherscanSource(String address) |
static com.u7.jthereum.internal.EtherscanSourceCodeDetails |
generateJavaProxyFromEtherscanSource(String blockchainName,
String address) |
static com.u7.jthereum.internal.EtherscanSourceCodeDetails |
generateJavaProxyFromEtherscanSource(String blockchainName,
String address,
String packageName) |
static java.math.BigInteger |
getBalance()
Gets the balance (in Wei) of the inferred account on the inferred blockchain.
|
static java.math.BigInteger |
getBalance(String blockchainName)
Gets the balance (in Wei) of the inferred account on the specified blockchain.
|
static java.math.BigInteger |
getBalance(String blockchainName,
String address)
Gets the balance (in Wei) of the specified account on the specified blockchain.
|
static com.u7.jthereum.support.BlockDetails |
getBlockDetails(String blockchainName,
java.math.BigInteger blockNumber)
Get BlockDetails of a specific block on the blockchain.
|
static com.u7.jthereum.support.BlockDetails |
getBlockDetails(String blockchainName,
long blockNumber)
Get BlockDetails of a specific block on the blockchain.
|
static java.math.BigInteger |
getCurrentBlockNumber(String blockchainName) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain() |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class contractClass) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class contractClass,
java.math.BigInteger startingBlock) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class contractClass,
java.math.BigInteger startingBlock,
java.math.BigInteger endingBlock) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class contractClass,
long startingBlock,
long endingBlock) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class _class,
String blockchainName) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class _class,
String blockchainName,
java.math.BigInteger startingBlock,
java.math.BigInteger endingBlock) |
static com.u7.jthereum.support.GenericEventLogItem[] |
getEventsFromBlockchain(Class _class,
String blockchainName,
String address) |
static JthereumProperties |
getJthereumProperties()
Gets the current JthereumProperties object in effect.
|
static String |
getMyAddress()
Gets the address that will be used with the inferred blockchain.
|
static String |
getMyAddress(String blockchainName)
Gets the address that will be used with the named blockchain.
|
static JthereumProperties |
getThreadLocalJthereumProperties()
Returns the JthereumProperties object that is specific to this thread, if any.
|
static void |
p(Object s)
Convenience method to print out an object as a string.
|
static boolean |
sendAllEth(String blockchainName,
java.math.BigInteger fromPK,
String toAddress)
Sends *all* the Wei from the account associated with fromPK to toAddress.
|
static boolean |
sendEth(String blockchainName,
java.math.BigInteger fromPK,
String toAddress,
java.math.BigInteger amount)
Sends the specified amount of Wei to 'toAddress'.
|
static boolean |
sendEth(String blockchainName,
java.math.BigInteger fromPK,
String toAddress,
long amount)
Sends the specified amount of Wei to 'toAddress'.
|
static boolean |
sendEth(String blockchainName,
String toAddress,
java.math.BigInteger amount)
Sends the specified amount of Wei to 'toAddress'.
|
static boolean |
sendEth(String blockchainName,
String toAddress,
long amount)
Sends the specified amount of Wei to 'toAddress'.
|
static String |
weiAmountToString(java.math.BigInteger amount)
Format a Wei amount to show the value in terms of ETH (as a floating point value), and Wei (as an exact integer value).
|
public static final java.math.BigInteger ETHER
public static final java.math.BigInteger FINNEY
public static final java.math.BigInteger GWEI
public static final java.math.BigInteger SZABO
public static final java.math.BigInteger WEI
public static String compile()
Compiles the class containing the main() method that was invoked.
This method is mainly for checking for translation errors. Normally you would call compileAndDeploy()
public static String compile(Class _class)
This method is mainly for checking for tranlation errors. Normally you would call compileAndDeploy()
_class
- the class to be compiledpublic static String compileAndDeploy()
The class to compile is the class containing the main() method that is executing.
public static String compileAndDeploy(boolean verifySource)
verifySource
- true iff the contract source code should be verified on https://etherscan.iopublic static String compileAndDeploy(Class _class)
_class
- the class to compilepublic static String compileAndDeploy(Class _class, boolean verifySource)
_class
- the class to compileverifySource
- true iff the contract source code should be verified on https://etherscan.iopublic static String compileAndDeploy(Class _class, String blockchainName)
_class
- the class to compileblockchainName
- the name of the blockchain to deploy topublic static String compileAndDeploy(Class _class, String blockchainName, boolean verifySource)
_class
- the class to compileblockchainName
- the name of the blockchain to deploy toverifySource
- true iff the contract source code should be verified on https://etherscan.iopublic static String compileAndDeploy(String blockchainName)
The class to compile is the class containing the main() method that is executing.
blockchainName
- the name of the blockchain to deploy topublic static String compileAndDeploy(String blockchainName, boolean verifySource)
The class to compile is the class containing the main() method that is executing.
blockchainName
- the name of the blockchain to deploy toverifySource
- true iff the contract source code should be verified on https://etherscan.iopublic static Object createProxy()
The Proxy Object will be of a class derived from the class containing the main() method that was run.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM.
Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
Since the blockchainName is not specified, it will be inferred from the OVERRIDE_BLOCKCHAIN property, if present, else from the first @DefaultContractLocation annotation, if present, else from the most recent successful deployment of this contract, else from the DEFAULT_BLOCKCHAIN property, if present, else it will default to "test".
Since the address of the contract is not specified it will be inferred from an @DefaultContractLocation annotation on the contract, or if not present then the address will be inferred from deloyment address of the most recent successful deployment of this contract (if any).
public static <T> T createProxy(Class<T> _class)
The Proxy Object will be of a class derived from the given class.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM.
Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
Since the blockchainName is not specified, it will be inferred from the OVERRIDE_BLOCKCHAIN property, if present, else from the first @DefaultContractLocation annotation, if present, else from the most recent successful deployment of this contract, else from the DEFAULT_BLOCKCHAIN property, if present, else it will default to "test".
Since the address of the contract is not specified it will be inferred from an @DefaultContractLocation annotation on the contract, or if not present then the address will be inferred from deloyment address of the most recent successful deployment of this contract (if any).
T
- the type of the proxy object to be created and returned_class
- the contract class to wrap in a proxypublic static <T> T createProxy(Class<T> _class, String blockchainName)
The Proxy Object will be of a class derived from the given class.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM.
Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
Since the address of the contract is not specified it will be inferred from an @DefaultContractLocation annotation on the contract, or if not present then the address will be inferred from deloyment address of the most recent successful deployment of this contract (if any).
T
- the type of the proxy object to be created and returned_class
- the contract class to wrap in a proxyblockchainName
- the blockchain to usepublic static <T> T createProxy(Class<T> _class, String blockchainName, String contractAddress)
The Proxy Object will be of a class derived from the given class.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM. Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
T
- the type of the proxy object to be created and returned_class
- the contract class to wrap in a proxyblockchainName
- the blockchain to usecontractAddress
- the address that the contract is deployed atpublic static Object createProxy(String blockchainName)
The Proxy Object will be of a class derived from the class containing the main() method that was run.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM.
Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
Since the address of the contract is not specified it will be inferred from an @DefaultContractLocation annotation on the contract, or if not present then the address will be inferred from deloyment address of the most recent successful deployment of this contract (if any).
blockchainName
- the blockchain to usepublic static Object createProxy(String blockchainName, String contractAddress)
The Proxy Object will be of a class derived from the class containing the main() method that was run.
Certain method calls will be executed on the local JVM, rather than being delgated to calls to the blockchain. Specifically, static methods, and methods annotated with @JavaSideExecutionOnly will be executed on the local JVM.
Note that any methods that you intend to call directly on the blockchain *must* be marked 'public'
blockchainName
- the blockchain to usecontractAddress
- the address that the contract is deployed atpublic static boolean doesAddressContainContract(String blockchainName, String address)
NOTE: This method is still experimental! May not be fully reliable.
blockchainName
- the blockchain to useaddress
- the address to checkpublic static com.u7.jthereum.internal.EtherscanSourceCodeDetails generateJavaProxyFromEtherscanSource(String address)
public static com.u7.jthereum.internal.EtherscanSourceCodeDetails generateJavaProxyFromEtherscanSource(String blockchainName, String address)
public static com.u7.jthereum.internal.EtherscanSourceCodeDetails generateJavaProxyFromEtherscanSource(String blockchainName, String address, String packageName)
public static java.math.BigInteger getBalance()
The account will be inferred from the privateKey set in the JthereumProperties object.
public static java.math.BigInteger getBalance(String blockchainName)
The account will be inferred from the privateKey set in the JthereumProperties object.
blockchainName
- the blockchain to usepublic static java.math.BigInteger getBalance(String blockchainName, String address)
blockchainName
- the blockchain to useaddress
- the address to get the blance ofpublic static com.u7.jthereum.support.BlockDetails getBlockDetails(String blockchainName, java.math.BigInteger blockNumber)
blockchainName
- blockchain nameblockNumber
- block number as a BigInteger (for that day when there are more than 2^63 blocks... ;)public static com.u7.jthereum.support.BlockDetails getBlockDetails(String blockchainName, long blockNumber)
blockchainName
- blockchain nameblockNumber
- block number as a longpublic static java.math.BigInteger getCurrentBlockNumber(String blockchainName)
public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain()
public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class contractClass)
contractClass
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class contractClass, java.math.BigInteger startingBlock)
contractClass
- startingBlock
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class contractClass, java.math.BigInteger startingBlock, java.math.BigInteger endingBlock)
contractClass
- startingBlock
- endingBlock
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class contractClass, long startingBlock, long endingBlock)
contractClass
- startingBlock
- endingBlock
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class _class, String blockchainName)
_class
- blockchainName
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class _class, String blockchainName, java.math.BigInteger startingBlock, java.math.BigInteger endingBlock)
_class
- blockchainName
- startingBlock
- endingBlock
- public static com.u7.jthereum.support.GenericEventLogItem[] getEventsFromBlockchain(Class _class, String blockchainName, String address)
_class
- blockchainName
- address
- public static JthereumProperties getJthereumProperties()
The JthereumProperties object contains the properties that were loaded from 'jthereum.comfig' in the installation directory (or from the 'jthereum.properties' file, if it exists in the current directory).
JthereumProperties
public static String getMyAddress()
public static String getMyAddress(String blockchainName)
blockchainName
- the blockchain to usepublic static JthereumProperties getThreadLocalJthereumProperties()
public static void p(Object s)
Just a shortcut method that does System.out.println(s)
s
- the object to printpublic static boolean sendAllEth(String blockchainName, java.math.BigInteger fromPK, String toAddress)
The Ether comes from the account associated with the private key value retrieved from the JthereumProperties object.
The gasLimit will be set to 21,000, which means that any attempt to send the Eth to the @FallbackFunction of a contract will fail if that function consumes any gas. To send Eth to such a contract use sendEth() which uses a gasLimit of 40,000 by default to pay the gas for a small @FallbackFunction if needed.
blockchainName
- name of the blockchain to do the transaction onfromPK
- the private key for the account sending the ETHtoAddress
- desitnation address to send the Wei topublic static boolean sendEth(String blockchainName, java.math.BigInteger fromPK, String toAddress, java.math.BigInteger amount)
The Ether comes from the account associated with the private key value retrieved from the JthereumProperties object.
blockchainName
- name of the blockchain to do the transaction onfromPK
- the private key for the account sending the ETHtoAddress
- desitnation address to send the Wei toamount
- amount of Wei to sendpublic static boolean sendEth(String blockchainName, java.math.BigInteger fromPK, String toAddress, long amount)
The Ether comes from the account associated with the private key value retrieved from the JthereumProperties object.
blockchainName
- name of the blockchain to do the transaction onfromPK
- the private key for the account sending the ETHtoAddress
- desitnation address to send the Wei toamount
- amount of Wei to sendpublic static boolean sendEth(String blockchainName, String toAddress, java.math.BigInteger amount)
The Ether comes from the account associated with the private key value retrieved from the JthereumProperties object.
blockchainName
- name of the blockchain to do the transaction ontoAddress
- desitnation address to send the Wei toamount
- amount of Wei to sendpublic static boolean sendEth(String blockchainName, String toAddress, long amount)
The Ether comes from the account associated with the private key value retrieved from the JthereumProperties object.
blockchainName
- name of the blockchain to do the transaction ontoAddress
- desitnation address to send the Wei toamount
- amount of Wei to sendpublic static String weiAmountToString(java.math.BigInteger amount)
amount
- the amount of Wei