transfer static method
Future<TransferResult>
transfer({
- required AgentFactory agent,
- required String to,
- required BigInt amount,
- SendOpts? sendOpts,
- SignIdentity? identity,
Implementation
static Future<TransferResult> transfer({
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
? null
: {
'timestamp_nanos':
sendOpts?.createAtTime?.millisecondsSinceEpoch.toBn(),
},
};
final res = await ledgerInstance.agent.actor!.getFunc(
LedgerMethods.transfer,
)!([TransferArgs.fromJson(sendArgs).toJson()]);
if (res != null) {
return TransferResult.fromJson(res as Map);
}
throw StateError('Request failed with the result: $res.');
}