I am using https://pub.dev/packages/flutter_web3
in order to connect my Flutter Web App with Solidity smart contract.
I could successfully connect with Metamask with my account
Future<bool> connectProvider() async {
debugPrint("connectProvider");
if (Ethereum.isSupported) {
final accs = await ethereum!.requestAccount();
if (accs.isNotEmpty) {
debugPrint("accounts not empty");
currentAddress = accs.first;
currentChain = await ethereum!.getChainId();
debugPrint("current chain is $currentChain");
debugPrint("current address $currentAddress");
} else {
debugPrint("accounts are empty");
}
} else {
debugPrint("not supported");
}
return false;
}
I could also get data about my balance:
Future<bool> getBalance() async {
final rpcProvider = JsonRpcProvider('https://bsc-dataseed1.defibit.io/');
final lastBlock = await rpcProvider.getLastestBlock();
final balance = await rpcProvider.getBalance(address);
BigInt balanceFormatted = BigInt.from(10).pow(18);
double b = balance / balanceFormatted;
debugPrint("balance = $b");
return false;
}
The problem appears when I am trying to fetch information from smart contract:
final contract = Contract(smartContactAddress, jsonAbi, rpcProvider);
final something = await contract.call<String>('address');
debugPrint("something = $something");
Where method in abi file is:
{
"inputs": [],
"name": "pick_address",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "pure",
"type": "function"
}
Here's the output:
js_util_patch.dart:80 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
at Object.callMethod$ [as callMethod] (js_util_patch.dart:80:66)
at ethers.Contract.__._call (contract.dart:193:43)
at _call.next (<anonymous>)
.....
Which is referring to this method:
@patch
T callMethod<T>(Object o, String method, List<Object?> args) {
assertInteropArgs(args);
return JS<dynamic>('Object|Null', '#[#].apply(#, #)', o, method, o, args);
}
Maybe anyone has a workaround for that or does know if I pass something in the wrong way.
EDIT
I have found some workaround to GET uint256
values from smart contract, but still cannot retrieve the value with type address
. Post is edited. What is the equivalent type of address in flutter?