-
Notifications
You must be signed in to change notification settings - Fork 2
Transaction Transfer
Wei Hau Lim edited this page May 12, 2022
·
4 revisions
Transfer transaction is used to send assets between two accounts. It can hold a message of length 1024. To create Transfer Transaction use TransferTransaction.create().
- Following parameters required:
- Recipient - The address of the recipient account.
- Mosaics - The List of mosaics to be sent.
- Message - The transaction message of 1024 characters.
import 'package:xpx_chain_sdk/xpx_sdk.dart';
const baseUrl = 'http://bctestnet3.brimstone.xpxsirius.io:3000';
/// Creating a client instance
/// xpx_chain_sdk uses the Dart's native HttpClient.
/// Depending on the platform, you may want to use either
/// the one which comes from dart:io or the BrowserClient
/// example:
/// 1- import 'package:http/browser_client.dart';
/// 2- var client = newClient(config, BrowserClient());
final client = SiriusClient.fromUrl(baseUrl, null);
/// Simple Account API AnnounceTransaction
void main() async {
final generationHash = await client.generationHash;
final networkType = await client.networkType;
/// Create an Account from a given Private key.(signer/sender)
final account = await Account.fromPrivateKey(
'5D39DFFB41BB92C5932C29BAB4E1E5AC2C1901784BF008DC937A8A460B925331',
networkType);
/// Create an Address from a given Public key. (recipient)
final recipient =
Address.fromRawAddress('VC4XVXBWAR4JQ3NHCKS7PUHPZJKLXSWRVYXMDWW7');
/// Create a transfer transaction
final transaction = TransferTransaction.create(
// The maximum amount of time to include the transaction in the blockchain.
Deadline(hours: 1),
// The Address of the recipient account.
recipient,
// The List of mosaics to be sent.
[xpx(10)],
// The transaction message (max 1024 characters).
PlainMessage(payload: 'From ProximaX Dart SDK'),
networkType);
final signedTransaction =
await account.signTransaction(transaction, generationHash);
try {
final restTx = await client.transaction.announce(signedTransaction);
print(restTx);
print('Hash: ${signedTransaction.hash}');
print('Signer: ${account.publicAccount.publicKey}');
} on Exception catch (e) {
print('Exception when calling Transaction->Announce: $e\n');
}
}