id | title |
---|---|
examples |
Examples |
import org.arkecosystem.crypto.transactions.Transaction;
import org.arkecosystem.crypto.transactions.builder.Transfer;
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.
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 nonces work go to the following link: https://learn.ark.dev/concepts/understanding-transaction-nonce
Transaction actual = new TransferBuilder()
.recipient("validAddress")
.amount(10^8) // amount of arktoshis we want to send
.nonce("1")
.vendorField("This is a transaction from Java")
.sign("this is a top secret passphrase")
.transaction;
>>> Transfer
Transaction actual = new MultiPaymentBuilder()
.addPayment("validAddress", 10^8)
.addPayment("validAddress", 10^8)
.addPayment("validAddress", 10^8)
.nonce("1")
.sign("this is a top secret passphrase")
.transaction;
>>> MultiPayment
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.
import org.arkecosystem.crypto.transactions.Serializer;
byte[] bytes = Serializer.serialize(transaction);
String serializedHex = Arrays.toString(bytes);
>>> String
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.
import org.arkecosystem.crypto.transactions.Deserializer;
Transaction transaction = new Deserializer("serialized-hex").deserialize();
>>> void
The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).
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
orpassphrase
.
import org.arkecosystem.crypto.utils.Message;
Message message = Message.sign("Hello World", "this is a top secret passphrase");
>>> Message
A message's signature can easily be verified by hash, without the private key that signed the message, by using the
verify
method.
import org.arkecosystem.crypto.utils.Message;
Message message = Message.sign("Hello World", "this is a top secret passphrase");
System.out.println(message.verify());
>>> boolean
The identities class allows for the creation and inspection of keypairs from
passphrases
. Here you find vital functions when creating transactions and managing wallets.
import org.arkecosystem.crypto.identities.Address;
Address.fromPassphrase("this is a top secret passphrase");
>>> string
import org.arkecosystem.crypto.identities.Address;
Address.fromPublicKey("validPublicKey");
>>> String
import org.arkecosystem.crypto.identities.Address;
Address.fromPrivateKey("validPrivateKey");
>>> String
import org.arkecosystem.crypto.identities.Address;
Address.validate("validAddress");
>>> Boolean
As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets
import org.arkecosystem.crypto.identities.PrivateKey;
PrivateKey.fromPassphrase("this is a top secret passphrase").getPrivateKeyAsHex();
>>> ECKey
import org.arkecosystem.crypto.identities.PrivateKey;
PrivateKey.fromHex("validHexString").getPrivateKeyAsHex();
>>> ECKey
This function has not been implemented in this client library.
Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.
import org.arkecosystem.crypto.identities.PublicKey;
PublicKey.fromPassphrase("this is a top secret passphrase");
>>> String
This function has not been implemented in this client library.
This function has not been implemented in this client library.
The WIF should remain secret, just like your
passphrase
andprivate key
.
import org.arkecosystem.crypto.identities.WIF;
WIF.fromPassphrase("this is a top secret passphrase");
>>> String