transferLamports method

Future<TransactionId> transferLamports({
  1. required Ed25519HDKeyPair source,
  2. required Ed25519HDPublicKey destination,
  3. required int lamports,
  4. String? memo,
  5. SignatureCallback? onSigned,
  6. Commitment commitment = Commitment.finalized,
})

Creates a solana transfer message to send lamports SOL tokens from source to destination.

To add additional data to the transaction you can use the memo field. It accepts an arbitrary string of utf-8 characters. As of now the maximum allowed length for the memo is 566 bytes of utf-8 data.

Implementation

Future<TransactionId> transferLamports({
  required Ed25519HDKeyPair source,
  required Ed25519HDPublicKey destination,
  required int lamports,
  String? memo,
  SignatureCallback? onSigned,
  Commitment commitment = Commitment.finalized,
}) {
  final instructions = [
    SystemInstruction.transfer(
      fundingAccount: source.publicKey,
      recipientAccount: destination,
      lamports: lamports,
    ),
    if (memo != null)
      MemoInstruction(signers: [source.publicKey], memo: memo),
  ];

  return sendAndConfirmTransaction(
    message: Message(instructions: instructions),
    signers: [source],
    onSigned: onSigned ?? ignoreOnSigned,
    commitment: commitment,
  );
}