API Documentation
Identity
Derive an address from a passphrase
public static String fromPassphrase(String passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase to derive the address. |
Return Value
This method returns an address derived from the given passphrase in string format.
String address = Address.fromPassphrase("super secret passphrase");
>> "0x2289577F3784788784226Eb41E9B0ca9705C7C37"
Type | Name | Required | Description |
---|---|---|---|
String | publicKey | Yes | Public key to derive the address. |
Return Value
This method returns an address derived from the given public key in string format.
String address = Address.fromPublicKey("validPublicKey");
>> "0x2289577F3784788784226Eb41E9B0ca9705C7C37"
Derive an address from a private key
public static String fromPrivateKey(ECKey privateKey)
Parameters
Type | Name | Required | Description |
---|---|---|---|
ECKey | privateKey | Yes | Private key to derive the address. |
Return Value
This method returns an address derived from the given private key in string format.
String address = Address.fromPrivateKey(privateKey);
>> "0x2289577F3784788784226Eb41E9B0ca9705C7C37"
Type | Name | Required | Description |
---|---|---|---|
String | address | Yes | Address to validate. |
Return Value
This method returns a boolean indicating whether the address is valid.
boolean isValid = Address.validate("0x2289577F3784788784226Eb41E9B0ca9705C7C37");
>> true
Derive a private key from a passphrase
public static ECKey fromPassphrase(String passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase to derive the private key. |
Return Value
This method returns a private key object derived from the given passphrase.
ECKey privateKey = PrivateKey.fromPassphrase("super secret passphrase");
>> ECKey
Type | Name | Required | Description |
---|---|---|---|
String | privateKey | Yes | Hexadecimal string representing the private key. |
Return Value
This method returns a private key object derived from the given hex string.
ECKey privateKey = PrivateKey.fromHex("validHexString");
>> ECKey
Derive a public key from a passphrase
public static String fromPassphrase(String passphrase)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase to derive the public key. |
Return Value
This method returns a public key in hexadecimal string format derived from the given passphrase.
String publicKey = PublicKey.fromPassphrase("super secret passphrase");
>> "02d1c19f660a2725f55fad7864202b98671538381c0c77f57b8961ada0d1d61c1b"
Type | Name | Required | Description |
---|---|---|---|
String | publicKey | Yes | Public key in hexadecimal string format. |
Return Value
This method returns the public key in the same hexadecimal format.
String publicKey = PublicKey.fromHex("validHexString");
>> "validHexString"
Derive a WIF from a passphrase
public static String fromPassphrase(String passphrase) throws IOException
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase to derive the WIF. |
Return Value
This method returns a WIF string derived from the given passphrase.
String wif = WIF.fromPassphrase("super secret passphrase");
>> "L2KVU2v4a1kgwem1S7LhWhTkzwMBvd1aR9Kh8itwu1c7cnRXAUxE"
Network
This method returns the current network configuration object.
INetwork currentNetwork = Network.get();
>> Mainnet // or `Devnet` or `Testnet`
Type | Name | Required | Description |
---|---|---|---|
INetwork | network | Yes | Network configuration to set (e.g., Mainnet, Devnet, Testnet). |
Return Value
This method sets the network configuration to the provided object.
Network.set(new Mainnet());
Transactions
Type | Name | Required | Description |
---|---|---|---|
int | gasLimit | Yes | Gas limit for the transaction. |
Return Value
This method sets the gas limit of the transaction and returns the builder instance.
builder.gasLimit(1000000);
Set the transaction recipient address
public TBuilder recipientAddress(String recipientAddressId)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | recipientAddressId | Yes | Recipient address for the transaction. |
Return Value
This method sets the recipient address of the transaction and returns the builder instance.
builder.recipientAddress("0x1234567890abcdef");
Type | Name | Required | Description |
---|---|---|---|
int | gasPrice | Yes | Gas price for the transaction. |
Return Value
This method sets the gas price of the transaction and returns the builder instance.
builder.gasPrice(50000000000);
Type | Name | Required | Description |
---|---|---|---|
long | nonce | Yes | Nonce for the transaction. |
Return Value
This method sets the nonce of the transaction and returns the builder instance.
builder.nonce(1);
Type | Name | Required | Description |
---|---|---|---|
int | network | Yes | Network version for the transaction. |
Return Value
This method sets the network version of the transaction and returns the builder instance.
builder.network(23);
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase to sign the transaction. |
Return Value
This method signs the transaction with the given passphrase and returns the builder instance.
builder.sign("super secret passphrase");
This method verifies the transaction and returns a boolean indicating validity.
boolean isValid = builder.verify();
This method converts the transaction to a JSON string and returns it.
String json = builder.toJson();
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Set the payload for the EVM call transaction
public EvmCallBuilder payload(String payload)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | payload | Yes | Payload data for the EVM call transaction. |
Return Value
This method sets the payload for the EVM call transaction, removing any leading '0x' if present, and returns the builder instance.
EvmCallBuilder builder = (new EvmCallBuilder()).payload("payloadData");
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Type | Name | Required | Description |
---|---|---|---|
String | value | Yes | Value to transfer in the transaction. |
Return Value
This method sets the value for the transfer transaction, refreshes the payload data, and returns the builder instance.
TransferBuilder builder = (new TransferBuilder()).value("1000000");
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Set the validator public key
public ValidatorRegistrationBuilder validatorPublicKey(String validatorPublicKey)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | validatorPublicKey | Yes | Public key for the validator registration. |
Return Value
This method sets the validator public key for the registration and returns the builder instance.
ValidatorRegistrationBuilder builder = (new ValidatorRegistrationBuilder()).validatorPublicKey("yourValidatorPublicKey");
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Inherits from: ...Builder\AbstractTransactionBuilder
see transaction builder docs
Type | Name | Required | Description |
---|---|---|---|
String | vote | Yes | The vote to set for the transaction. |
Return Value
This method sets the vote for the transaction and returns the builder instance.
VoteBuilder builder = (new VoteBuilder()).vote("yourVote");
This method computes the transaction ID and sets it to the `id` field.
transaction.computeId();
This method returns the transaction ID as a string.
String transactionId = transaction.getId();
Type | Name | Required | Description |
---|---|---|---|
String | passphrase | Yes | Passphrase used to sign the transaction. |
Return Value
This method signs the transaction with the provided passphrase and returns the transaction instance.
transaction.sign("super secret passphrase");
This method recovers the sender's public key and address from the transaction signature.
transaction.recoverSender();
This method verifies the transaction signature and returns `true` if valid, otherwise `false`.
boolean isValid = transaction.verify();
This method converts the transaction to a JSON string.
String json = transaction.toJson();
This method converts the transaction to a HashMap representation.
HashMap<String, Object> map = transaction.toHashMap();
Type | Name | Required | Description |
---|---|---|---|
boolean | skipSignature | No | Whether to skip the signature in serialization. |
Return Value
This method serializes the transaction into a byte array with an option to skip the signature.
byte[] serializedTransaction = transaction.serialize(false);
Decode the transaction payload
public List<Object> decodePayload(Map<String, Object> data)
Parameters
Type | Name | Required | Description |
---|---|---|---|
Map<String, Object> | data | Yes | Data map containing the transaction payload. |
Return Value
This method decodes the transaction payload and returns a list of arguments.
List<Object> payload = transaction.decodePayload(data);
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Inherits from: ...types.AbstractTransaction
see AbstractTransaction docs
Serializer
Create a new Serializer instance
public static Serializer newSerializer(AbstractTransaction transaction)
Parameters
Type | Name | Required | Description |
---|---|---|---|
AbstractTransaction | transaction | Yes | The transaction object to serialize. |
Return Value
This method creates a new Serializer instance for the given transaction.
Serializer serializer = Serializer.newSerializer(transaction);
Get serialized transaction bytes
public static byte[] getBytes(AbstractTransaction transaction, boolean skipSignature)
Parameters
Type | Name | Required | Description |
---|---|---|---|
AbstractTransaction | transaction | Yes | The transaction to serialize. |
boolean | skipSignature | Yes | Whether to skip including the signature in serialization. |
Return Value
This method serializes the transaction and returns the resulting byte array.
byte[] transactionBytes = Serializer.getBytes(transaction, false);
Type | Name | Required | Description |
---|---|---|---|
boolean | skipSignature | Yes | Whether to skip the signature in the serialized output. |
Return Value
This method serializes the transaction to a byte array with an option to skip the signature.
byte[] serializedTransaction = serializer.serialize(false);
Deserializer
Create a new Deserializer instance
public static Deserializer newDeserializer(String serialized)
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | serialized | Yes | The serialized transaction string. |
Return Value
This method creates a new Deserializer instance for the provided serialized transaction string.
Deserializer deserializer = Deserializer.newDeserializer("serialized transaction string");
This method deserializes the transaction from the buffer and returns an AbstractTransaction object.
AbstractTransaction transaction = deserializer.deserialize();
Message
Type | Name | Required | Description |
---|---|---|---|
String | message | Yes | The message to be signed. |
String | passphrase | Yes | The passphrase used to sign the message. |
Return Value
This method signs a message using the provided passphrase and returns a Message object containing the message, signature, and public key.
Message signedMessage = Message.sign("Hello, world!", "super secret passphrase");
This method verifies the signature of the message and returns true if valid, otherwise false.
boolean isValid = signedMessage.verify();
This method converts the message into a Map containing the message, public key, and signature.
Map<String, Object> messageMap = signedMessage.toMap();
This method converts the message to a JSON string representation.
String jsonMessage = signedMessage.toJson();
This method returns the original message.
String originalMessage = signedMessage.getMessage();
This method returns the public key used to sign the message.
String publicKey = signedMessage.getPublickey();
This method returns the signature of the message.
String signature = signedMessage.getSignature();
Slot
This method returns the current network time in seconds since the network epoch.
int currentNetworkTime = Slot.time();
This method returns the network epoch time in milliseconds since January 1, 1970.
long networkEpochTime = Slot.epoch();
ABI Decoder
Decode function data from ABI
public Map<String, Object> decodeFunctionData(String data) throws Exception
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | data | Yes | Hexadecimal string representing the encoded ABI function call. |
Return Value
This method decodes the function name and parameters from the given ABI-encoded data, returning a map containing the function name and arguments.
AbiDecoder decoder = new AbiDecoder();
Map<String, Object> decodedData = decoder.decodeFunctionData("0x0123456789abcdef...");
>> {functionName="transfer", args=["0x1234...", "1000"]}
ABI Encoder
Encode a function call without parameters
public String encodeFunctionCall(String functionName) throws Exception
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | functionName | Yes | Name of the function to encode. |
Return Value
This method encodes a function call with no parameters into ABI format.
AbiEncoder encoder = new AbiEncoder();
String encodedCall = encoder.encodeFunctionCall("transfer");
>> "0xa9059cbb"
Encode a function call with parameters
public String encodeFunctionCall(String functionName, List<Object> args) throws Exception
Parameters
Type | Name | Required | Description |
---|---|---|---|
String | functionName | Yes | Name of the function to encode. |
List<Object> | args | Yes | List of arguments to encode with the function call. |
Return Value
This method encodes a function call with the given parameters into ABI format.
AbiEncoder encoder = new AbiEncoder();
List<Object> args = Arrays.asList("0x1234...", 1000);
String encodedCall = encoder.encodeFunctionCall("transfer", args);
>> "0xa9059cbb0000000000000000000000001234...000000000000000000000000000003e8"