Examples

Initialization

1import org.arkecosystem.crypto.transactions.Transaction;
2import org.arkecosystem.crypto.transactions.builder.Transfer;

Transactions

A transaction is an object specifying the transfer of funds from the sender’s wallet to the recipient’s. Each transaction must be signed by the sender’s private key to prove authenticity and origin. After broadcasting through the client SDK , a transaction is permanently incorporated in the blockchain by a Delegate Node.

Sign

The crypto SDK can sign a transaction using your private key or passphrase (from which the private key is generated). Ensure you are familiar with digital signatures before using the crypto SDKs.

To learn more about how sequential nonces work go to the following link: Understanding Transaction Nonce

Transfer

1Transaction actual = new TransferBuilder()
2 .recipient("validAddress")
3 .amount(10^8) // amount of arktoshi we want to send
4 .nonce("1")
5 .vendorField("This is a transaction from Java")
6 .sign("this is a top secret passphrase")
7 .transaction;
8>>> Transfer

MultiPayment

1Transaction actual = new MultiPaymentBuilder()
2 .addPayment("validAddress", 10^8)
3 .addPayment("validAddress", 10^8)
4 .addPayment("validAddress", 10^8)
5 .nonce("1")
6 .sign("this is a top secret passphrase")
7 .transaction;
8 
9>>> MultiPayment

Serialize (AIP11)

Serialization of a transaction object ensures it is compact and properly formatted to be incorporated in the ARK blockchain. If you are using the crypto SDK in combination with the public API SDK, you should not need to serialize manually.

1import org.arkecosystem.crypto.transactions.Serializer;
2 
3 byte[] bytes = Serializer.serialize(transaction);
4 String serializedHex = Arrays.toString(bytes);
5 
6>>> String

Deserialize (AIP11)

A serialized transaction may be deserialized for inspection purposes. The public API does not return serialized transactions, so you should only need to deserialize in exceptional circumstances.

1import org.arkecosystem.crypto.transactions.Deserializer;
2 
3Transaction transaction = new Deserializer("serialized-hex").deserialize();
4 
5>>> void

Message

The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).

Sign

Signing a string works much like signing a transaction: in most implementations, the message is hashed, and the resulting hash is signed using the private key or passphrase.

1import org.arkecosystem.crypto.utils.Message;
2 
3Message message = Message.sign("Hello World", "this is a top secret passphrase");
4 
5>>> Message

Verify

A message’s signature can easily be verified by hash, without the private key that signed the message, by using the verify method.

1import org.arkecosystem.crypto.utils.Message;
2 
3Message message = Message.sign("Hello World", "this is a top secret passphrase");
4System.out.println(message.verify());
5 
6>>> boolean

Identities

The identities class allows for the creation and inspection of keyPairs from passphrases. Here you find vital functions when creating transactions and managing wallets.

Derive the Address from a Passphrase

1import org.arkecosystem.crypto.identities.Address;
2 
3Address.fromPassphrase("this is a top secret passphrase");
4 
5>>> string

Derive the Address from a Public Key

1import org.arkecosystem.crypto.identities.Address;
2 
3Address.fromPublicKey("validPublicKey");
4 
5>>> String

Derive the Address from a Private Key

1import org.arkecosystem.crypto.identities.Address;
2 
3Address.fromPrivateKey("validPrivateKey");
4 
5>>> String

Validate an Address

1import org.arkecosystem.crypto.identities.Address;
2 
3Address.validate("validAddress");
4 
5>>> Boolean

Private Key

As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets

Derive the Private Key from a Passphrase

1import org.arkecosystem.crypto.identities.PrivateKey;
2 
3PrivateKey.fromPassphrase("this is a top secret passphrase").getPrivateKeyAsHex();
4 
5>>> ECKey

Derive the Private Key Instance Object from a Hexadecimal Encoded String

1import org.arkecosystem.crypto.identities.PrivateKey;
2 
3PrivateKey.fromHex("validHexString").getPrivateKeyAsHex();
4 
5>>> ECKey

Derive the Private Key from a WIF

1This function has not been implemented in this client library.

Public Key

Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.

Derive the Public Key from a Passphrase

1import org.arkecosystem.crypto.identities.PublicKey;
2 
3PublicKey.fromPassphrase("this is a top secret passphrase");
4 
5>>> String

Derive the Public Key Instance Object from a Hexadecimal Encoded String

1This function has not been implemented in this client library.

Validate a Public Key

1This function has not been implemented in this client library.

WIF

The WIF should remain secret, just like your passphrase and private key.

Derive the WIF from a Passphrase

1import org.arkecosystem.crypto.identities.WIF;
2 
3WIF.fromPassphrase("this is a top secret passphrase");
4 
5>>> String
Last updated 3 years ago
Edit Page
Share: