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 {
try {
var ledgerInstance = Ledger.hook(agent)..setIdentity(identity);
var defaultFee = BigInt.from(10000);
var defaultMemo = getRandomValues(4).toBn(endian: Endian.big);
var sendArgs = {
"to": to,
"fee": {
"e8s": sendOpts?.fee ?? defaultFee,
},
"amount": {"e8s": amount},
"memo": sendOpts?.memo ?? defaultMemo,
"from_subaccount": null,
"created_at_time": sendOpts?.created_at_time == null
? null
: {
"timestamp_nanos":
sendOpts?.created_at_time?.millisecondsSinceEpoch.toBn()
},
};
var res = await ledgerInstance.agent.actor!
.getFunc(LedgerMethods.send)!([SendArgs.fromMap(sendArgs).toJson()]);
if (res != null) {
return res as BigInt;
}
throw "Cannot get count but $res";
} catch (e) {
rethrow;
}
}