The Dynamic SDK Web3Dart is a dart package that provides a few methods for interacting with the Ethereum blockchain. It connects to an Ethereum through web3dart node to send transactions, interact with smart contracts and much more!

Installation

Simply run the following in your terminal:
flutter pub add dynamic_sdk_web3dart
This will add a line like this to your package’s pubspec.yaml (and run an implicit flutter pub get):
dependencies:
  dynamic_sdk_web3dart: ^0.0.1-alpha.4

Main Features

1. Sign Message

Future<String> signMessage({
  required BaseWallet wallet,
  required String message,
}) async {
  final signedMessage = await DynamicSDK.instance.wallets.signMessage(
    wallet: wallet,
    message: message,
  );

  return signedMessage;
}

2. Send Transaction

Future<String> sendTransaction({
  required BaseWallet wallet,
  required String recipientAddress,
  required String amount,
}) async {
  final to = recipientAddress.trim();
  if (to.isEmpty) throw Exception('Recipient address is required');
  
  final amountStr = amount.trim();
  if (amountStr.isEmpty) throw Exception('Amount is required');

  final amountInWei =
      (double.parse(amountStr) * BigInt.from(10).pow(18).toDouble())
          .toInt();

  final tx = Transaction(
    from: EthereumAddress.fromHex(wallet.address),
    to: EthereumAddress.fromHex(to),
    value: EtherAmount.inWei(BigInt.from(amountInWei)),
  );

  final txHash = await DynamicSDK.instance.web3dart.sendTransaction(
    transaction: tx,
    wallet: wallet,
  );

  return txHash;
}

3. Interact with Contracts

Future<String> interactWithContract({
  required BaseWallet wallet,
  required String message,
}) async {
  final network = await DynamicSDK.instance.wallets.getNetwork(
    wallet: wallet,
  );

  final client = DynamicSDK.instance.web3dart.createPublicClient(
    chainId: network.intValue()!,
  );

  final gasPrice = await client.getGasPrice();

  final maxFeePerGas =
      gasPrice.getValueInUnitBI(EtherUnit.wei) * BigInt.from(2);

  final maxPriorityFeePerGas =
      gasPrice.getValueInUnitBI(EtherUnit.wei) * BigInt.from(2);

  final contract = DeployedContract(
    ContractAbi.fromJson(
      '[{"constant":false,"inputs":[{"name":"newMessage","type":"string"}],"name":"update","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initMessage","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]',
      '',
    ),
    EthereumAddress.fromHex('0x8b211dfebf490a648f6de859dfbed61fa22f35e0'),
  );

  final updateFunction = contract.function('update');

  final transaction = Transaction.callContract(
    contract: contract,
    maxFeePerGas: EtherAmount.inWei(maxFeePerGas),
    maxPriorityFeePerGas: EtherAmount.inWei(maxPriorityFeePerGas),
    function: updateFunction,
    parameters: [message],
  );

  final transactionHash = await DynamicSDK.instance.web3dart
      .sendTransaction(transaction: transaction, wallet: wallet);

  return transactionHash;
}
You can read more about our client package here.