-
Notifications
You must be signed in to change notification settings - Fork 8
/
batch_transactions.dart
49 lines (44 loc) · 1.31 KB
/
batch_transactions.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'dart:io';
import 'package:fuse_wallet_sdk/fuse_wallet_sdk.dart';
void main() async {
final credentials = EthPrivateKey.fromHex('WALLET_PRIVATE_KEY');
// Create a project: https://console.fuse.io/build
final publicApiKey = 'YOUR_PUBLIC_API_KEY';
final fuseSDK = await FuseSDK.init(
publicApiKey,
credentials,
);
final tokenAddress = EthereumAddress.fromHex('TOKEN_ADDRESS');
final recipientAddress = EthereumAddress.fromHex('RECIPIENT_ADDRESS');
final amountInWei = BigInt.parse('AMOUNT_IN_WEI');
// Approve and transfer ERC20 token in a single batch transaction
final res = await fuseSDK.executeBatch(
[
// Approve ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20ApproveCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
// Transfer ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20TransferCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
],
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();
print('Transaction hash: ${ev?.transactionHash}');
exit(1);
}