Define, sign, and announce a transfer transaction.
This guide will show you how to send 10 bitxor
from your account to Bob’s, whose address is BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ
.
Complete the getting started section.
Create a new account.
Load the account with enough bitxor
to pay for transaction fees.
From the home page of your Desktop Wallet, click on the “Transfer” tab.
2. Fill out the necessary information for the transfer transaction.
For this example, you need to specify that you are sending 10 BXR to Bob (BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ
). You can add a message, but it is not necessary in this case.
3. Once you have filled out all the information, click “Send”. A popup will show. Read and verify the information, then enter your wallet password and click “Confirm”.
4. You can verify that the transaction was successful by going back to the “Dashboard” tab. At first, it might show up under “Unconfirmed” transactions as the transaction becomes included in a block, but you should soon be able to see it under the “Confirmed” transactions.
In a new terminal, monitor the transactions involving the sender account to know if they are confirmed or rejected by the network.
bitxor-cli monitor all --address <YOUR-ADDRESS>
2. Open a new file and define the TransferTransaction.
Include Bob’s address as the recipient, and attach 10 bitxor
.
Token units in Bitxor are defined as absolute amounts. To get an absolute amount, multiply the number of assets you want to send by 10divisibility. For example, if the token had divisibility 2, to send 10 units (relative) you should define 1000 (absolute) instead.
// replace with recipient address
const rawAddress = 'BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = Address.createFromRawAddress(rawAddress);
const transferTransaction = TransferTransaction.create(
Deadline.create(epochAdjustment),
recipientAddress,
[currency.createRelative(10)],
PlainMessage.create('This is a test message'),
networkType,
UInt64.fromUint(2000000),
);
// replace with recipient address
const rawAddress = 'BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = bitxor_sdk_1.Address.createFromRawAddress(
rawAddress,
);
const transferTransaction = bitxor_sdk_1.TransferTransaction.create(
bitxor_sdk_1.Deadline.create(epochAdjustment),
recipientAddress, [currency.createRelative(10)],
bitxor_sdk_1.PlainMessage.create('This is a test message'),
networkType,
bitxor_sdk_1.UInt64.fromUint(2000000),
);
// replace with node endpoint
try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
"NODE_URL")) {
// replace with recipient address
final String rawAddress = "BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ";
final UnresolvedAddress recipientAddress = Address.createFromRawAddress(rawAddress);
final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
// replace with bitxor id
final TokenId networkCurrencyTokenId = new TokenId("5E62990DCAC5BE8A");
// replace with network currency divisibility
final Integer networkCurrencyDivisibility = 6;
// replace with relative amount of bitxor to send
final BigInteger amount = BigInteger.valueOf(10);
final Token token = new Token(networkCurrencyTokenId,
amount.multiply(BigInteger.valueOf(10).pow(networkCurrencyDivisibility)));
final TransferTransaction transferTransaction = TransferTransactionFactory
.create(
networkType,
recipientAddress,
Collections.singletonList(token),
PlainMessage.create("This is a test message"))
.maxFee(BigInteger.valueOf(2000000)).build();
As you may have noticed, transfer transactions require an array of tokens as a parameter. This permits sending transfer transactions with multiple tokens at the same time.
If you own more than one token, you can send them together in the same transaction:
[
new Token(new TokenId('7CDF3B117A3C40CC'), UInt64.fromUint(1000)),
new Token(
new TokenId('5E62990DCAC5BE8A'),
UInt64.fromUint(10 * Math.pow(10, 6)),
),
],
[
new bitxor_sdk_1.Token(
new bitxor_sdk_1.TokenId('7CDF3B117A3C40CC'),
bitxor_sdk_1.UInt64.fromUint(1000),
),
new bitxor_sdk_1.Token(
new bitxor_sdk_1.TokenId('5E62990DCAC5BE8A'),
bitxor_sdk_1.UInt64.fromUint(10 * Math.pow(10, 6)),
),
],
Arrays.asList(new Token(new TokenId("7CDF3B117A3C40CC"),
BigInteger.valueOf(1000)),
new Token(new TokenId("5E62990DCAC5BE8A"),
BigInteger.valueOf(10000000))),
3. Sign the transaction with your account.
Then, include the network generation hash seed to make the transaction only valid for your network.
To retrieve the network generation hash seed, open NODE_URL /node/info
in a new browser tab and copy meta.networkGenerationHashSeed
value.
// replace with sender private key
const privateKey =
'1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
const signedTransaction = account.sign(
transferTransaction,
networkGenerationHash,
);
console.log('Payload:', signedTransaction.payload);
console.log('Transaction Hash:', signedTransaction.hash);
// replace with sender private key
const privateKey =
'1111111111111111111111111111111111111111111111111111111111111111';
const account = bitxor_sdk_1.Account.createFromPrivateKey(
privateKey,
networkType,
);
const signedTransaction = account.sign(
transferTransaction,
networkGenerationHash,
);
console.log('Payload:', signedTransaction.payload);
console.log('Transaction Hash:', signedTransaction.hash);
// replace with private key
final String privateKey = "1111111111111111111111111111111111111111111111111111111111111111";
// replace with network generation hash
final String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
final Account account = Account
.createFromPrivateKey(privateKey, networkType);
final SignedTransaction signedTransaction = account
.sign(transferTransaction, generationHash);
Once signed, announce the transaction to the network.
const transactionRepository = repositoryFactory.createTransactionRepository();
const response = await transactionRepository
.announce(signedTransaction)
.toPromise();
console.log(response);
const transactionRepository = repositoryFactory.createTransactionRepository();
const response = await transactionRepository
.announce(signedTransaction)
.toPromise();
console.log(response);
final TransactionRepository transactionRepository = repositoryFactory
.createTransactionRepository();
transactionRepository.announce(signedTransaction).toFuture().get();
}
5. Open the terminal where you are monitoring the transaction’s status. The transaction should appear as confirmed after 30 seconds at most and the amount defined gets transferred from the sender’s account to the recipient’s account. If the terminal raises an error, you can check the error code description here.
Open a terminal window and run the following command to transfer 10 BXR from your default account.
Remember to replace BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ
with the recipient address you want to send tokens too
and @bitxor::10000000
with the desired absolute amount.
Optionally, you can set a custom message with the option --message
.
bitxor-cli transaction transfer --recipient-address BXRQ5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ --tokens "@bitxor::10000000" --message "This is a test message" --sync