The following describes basic blockchain interop function of SDK and defines relevant data structure.
Please use the following methods to initialize OntSDK use case before luanching JAVA SDK.
OntSdk ontSdk = OntSdk.getInstance();
ontSdk.setRpcConnection(url);
//ontSdk.setRestfulConnection(url)
Note: setRestfulConnection indicates that the connection is established using the restful interface, and setRpcConnection indicates that the connection is established using the rpc interface.
get the current block height
int height = ontSdk.getConnectMgr().getBlockHeight();
Block block = ontSdk.getConnectMgr().getBlock(9757);
get blockchain node count
System.out.println(ontSdk.getConnectMgr().getNodeCount());
System.out.println(ontSdk.getConnectMgr().getGenerateBlockTime());
get blockchain-based transaction
String info = ontSdk.getConnectMgr().getTransaction(hash);
System.out.println(info);
InvokeCodeTransaction t = (InvokeCodeTransaction) ontSdk.getConnectMgr().getRawTransaction(hash);
System.out.println(t);
Field
Type
Description
version
int
version
prevBlockHash
UInt256
scripthash of the previous block
transactionsRoot
UInt256
merkel root of all the transactions in the block
blockRoot
UInt256
block root
timestamp
int
block time stamp, unix time stamp
height
int
block height
consensusData
long
consensus data
nextBookKeeper
UInt160
bookkeeping contract scripthash of the next block
sigData
array
signature
bookKeepers
array
bookkeepers
hash
UInt256
hash value of the block
transactions
Transaction[]
transaction list in the block
Field
Type
Description
version
int
version
txType
TransactionType
transaction type
nonce
int
random number
attributes
TransactionAttribute[]
transaction attribute list
fee
Fee[]
transaction fee list
networkFee
long
network fee
sigs
Sign[]
signature array
payload
Payload
payload
Value
Type
Description
208
int
smart contract deployment
209
int
smart contract invocation
Field
Type
Description
pubKeys
array
public key array
M
int
M
sigData
array
signature value array
Field
Type
Description
amount
long
amount
payer
UInt160
payer
Field
Type
Description
usage
TransactionAttributeUsage
usage
data
byte[]
attribute value
TransactionAttributeUsage
Value
Type
Description
0
int
Nonce
32
int
Script
129
int
DescriptionUrl
144
int
Description