send static method
Future<BigInt>
send({
- required AgentFactory agent,
- required String to,
- required BigInt amount,
- SendOpts? sendOpts,
- SignIdentity? identity,
Implementation
static Future<BigInt> send({
required AgentFactory agent,
required String to,
required BigInt amount,
SendOpts? sendOpts,
SignIdentity? identity,
}) async {
final ledgerInstance = Ledger.hook(agent)..setIdentity(identity);
final defaultFee = BigInt.from(10000);
final defaultMemo = getRandomValues(4).toBn(endian: Endian.big);
final sendArgs = {
'to': to,
'fee': {
'e8s': sendOpts?.fee ?? defaultFee,
},
'amount': {'e8s': amount},
'memo': sendOpts?.memo ?? defaultMemo,
'from_subaccount': null,
'created_at_time': sendOpts?.createAtTime != null
? {
'timestamp_nanos':
sendOpts?.createAtTime?.millisecondsSinceEpoch.toBn(),
}
: null,
};
final res = await ledgerInstance.agent.actor!.getFunc(
LedgerMethods.send,
)!([SendArgs.fromJson(sendArgs).toJson()]);
if (res != null) {
return res as BigInt;
}
throw StateError('Request failed with the result: $res.');
}