sendTokens method Null safety
Sending Tokens
Creates a TX in order to deposit the amount
of SNR into the recipient
account. A succesful transaction will return a PaymentResponse
and will return null if the transaction fails.
final res = await MotorFlutter.to.deposit('did:snr:abc123', 3.29);
if (res == null) {
throw Exception('Failed to deposit SNR');
}
print(res); // prints: {txHash: '0x1234567890abcdef', amount: 3.29}
Next Steps
- Sonr Blockchain API Reference
Implementation
Future<PaymentResponse> sendTokens(String recipient, int amount, {String? memo}) async {
final res = await MotorFlutterPlatform.instance.issuePayment(PaymentRequest(
to: recipient,
from: address.value,
amount: Int64(amount),
memo: memo,
));
if (res == null) {
throw UnmarshalException<PaymentResponse>();
}
return res;
}