Skip to content

Commit

Permalink
update transfer to fix sending decimal values
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaaElattar committed Nov 6, 2024
1 parent 68d4fda commit 0450e35
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/tfchain_client/lib/src/balances.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ class Balances extends QueryBalances {
final Client client;

Future<void> transfer(
{required String address, required BigInt amount}) async {
if (amount <= BigInt.zero) {
{required String address, required double amount}) async {
if (amount <= 0) {
throw Exception("Amount must be a positive numeric value");
}

final keyring = Keyring();
final publicKey = keyring.decodeAddress(address);
MultiAddress multiAddress = Id(publicKey);

final scaleFactor = BigInt.from(10).pow(7);
final scaledAmount = (amount * scaleFactor.toDouble()).round();
final bigIntAmount = BigInt.from(scaledAmount);

final extrinsic = client.api.tx.balances
.transfer(dest: multiAddress, value: amount * BigInt.from(10).pow(7));
.transfer(dest: multiAddress, value: bigIntAmount);
await client.apply(extrinsic);
}

Expand Down

0 comments on commit 0450e35

Please sign in to comment.