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;
}