LTO Network
Search…
Java

Requirements

JDK 11

Accounts

Creation

Create an account from seed
1
import com.ltonetwork.client.core.AccountFactory;
2
String seed = "my seed phrase";
3
4
AccountFactory af = new AccountFactory('T');
5
Account acc = af.seed(seed);
Copied!
Create an account from sign public key
1
import com.ltonetwork.client.types.PublicKey;
2
import com.ltonetwork.client.core.AccountFactory;
3
4
PublicKey signPublicKey = new PublicKey("wJ4WH8dD88fSkNdFQRjaAhjFUZzZhV5yiDLDwNUnp6bYwRXrvWV8MJhQ9HL9uqMDG1n7XpTGZx7PafqaayQV8Rp", Encoding.BASE58);
5
6
AccountFactory af = new AccountFactory('T');
7
Account acc = af.createPublic(signPublicKey);
Copied!
Create an account from full info
1
import com.ltonetwork.client.types.Key;
2
import com.ltonetwork.client.types.KeyPair;
3
import com.ltonetwork.client.core.AccountFactory;
4
5
KeyPair signKeyPair = new KeyPair (
6
new PublicKey("wJ4WH8dD88fSkNdFQRjaAhjFUZzZhV5yiDLDwNUnp6bYwRXrvWV8MJhQ9HL9uqMDG1n7XpTGZx7PafqaayQV8Rp", Encoding.BASE58),
7
new PrivateKey("FkU1XyfrCftc4pQKXCrrDyRLSnifX1SMvmx1CYiiyB3Y", Encoding.BASE58),
8
Key.KeyType.ED25519
9
);
10
11
KeyPair encryptKeyPair = new KeyPair (
12
new PublicKey("BVv1ZuE3gKFa6krwWJQwEmrLYUESuUabNCXgYTmCoBt6", Encoding.BASE58),
13
new PrivateKey("BnjFJJarge15FiqcxrB7Mzt68nseBXXR4LQ54qFBsWJN", Encoding.BASE58),
14
Key.KeyType.CURVE25519
15
);
16
17
Address address = new Address("3JmCa4jLVv7Yn2XkCnBUGsa7WNFVEMxAfWe");
18
19
AccountFactory af = new AccountFactory('T');
20
Account acc = af.create(
21
signKeyPair,
22
encryptKeyPair,
23
address);
Copied!
Properties that are specified will be verified. Properties that are omitted will be generated where possible.

Signing (ED25519)

Sign a message
1
import com.ltonetwork.seasalt.sign.Signature;
2
3
Signature sig = account.sign("my message");
Copied!
Verify a signature
1
import com.ltonetwork.seasalt.sign.Signature;
2
3
String message = "my message";
4
Signature sig = account.sign(message);
5
boolean isValid = account.verify(sig, message); // True
Copied!

Encryption (X25519)

Encrypt a message for another account
1
String message = "my message";
2
3
byte[] encrypted = senderAccount.encrypt(recipientAccount, message);
Copied!
You can use senderAccount.encrypt(senderAccount, message); to encrypt a message for yourself.
Decrypt a message received from another account
1
String message = "my message";
2
3
byte[] decrypted = recipientAccount.decrypt(senderAccount, message);
Copied!
You can use senderAccount.encrypt(senderAccount, message); to decrypt a message from yourself.

Public layer

1
PublicNode publicNode = new PublicNode(new URI("https://testnet.lto.network"), "myApiKey");
2
3
int amount = 1000; // Amount of LTO to transfer
4
Address recipient = new Address("3JmCa4jLVv7Yn2XkCnBUGsa7WNFVEMxAfWe");
5
6
Transfer tx = new Transfer(amount, recipient);
7
tx.signWith(myAccount);
8
publicNode.broadcast(tx);
Copied!