Repository navigation
Value not in range: 32 #2
Description
Activity
hi @kaumudpa usually this error happens when the address you are calling is not a smart contract, are you sure you are calling the correct smart contract address at the right chain?
can you post an example of the code which always gives this error?Issue persists across plugins - Please check this thread for more details xclud/web3dart#46
Again, any help will be appericiated.
@kaumudpa can you please provide the code example which doesn't work for you? An Ethereum node can return 0x0 due to different reasons
@makinghappen I have explained this in the other plugin's issue -
Try fetching balance of a token via webthree.
Interstingly If we use direct RPC client - things work just fine.
Injected Metamask as a custom client throws this issue.
With the help of alchemy explorer i found the following-
While using Alchemy API as Direct RPC Client the request to alchemy is
{"id":"d17acd83-3c00-432a-b3cd-1036985e9c2d","jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x7872eF9f1187bae5a522DDd0f29258e09976CEaE","data":"0x70a08231000000000000000000000000fad3b616bcd747a12a7c0a6203e7a481606b12e8"},"0x1f1b14b"]}Response
{"jsonrpc":"2.0","id":"d17acd83-3c00-432a-b3cd-1036985e9c2d","result":"0x00000000000000000000000000000000000000000000000fc26804b0a01683f7"}
While using injected metamask as custom client for the same request.
{"id":2465261209,"jsonrpc":"2.0","method":"eth_call","params":[{},"0x1f1b2ad"]}Response
{"jsonrpc":"2.0","id":2465261209,"result":"0x"}For some reason with custom client the request doesn't send the right params as you might have observed and hence we get just 0x as response and that's the reason webthree throws RangeError: Value not in range: 32
@kaumudpa how are you connecting metamask as a custom client, via package:webthree/browser.dart ?
- Yes!…On Sun, 12 Mar 2023 at 3:48 AM, makinghappen ***@***.***> wrote: @kaumudpa <https://github.com/kaumudpa> how are you connecting metamask as a custom client, via package:webthree/browser.dart ? — Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADHE2NAUPHENP6C4BQVKFNDW3T22DANCNFSM6AAAAAAVNNUDVQ> . You are receiving this because you were mentioned.Message ID: ***@***.***>
@kaumudpa can you share your code?
@makinghappen Check this
//Custom client : final client = Web3Client.custom(window.ethereum!.asRpcService()); //Call contract method await client.call( sender: EthereumAddress.fromHex(walletAddress), contract: deployedContractObj, function: deployedContractObj.function(functionName), params: parameters) .then((results) async { debugPrint('....${results}'); return BigInt.parse('${results}'); }).catchError((onError, trace) { debugPrint('Error....$onError'); debugPrint('Trace....$trace'); return BigInt.from(0); }); ```@kaumudpa you said you are trying to check balance, can you please share your full example code which fails?
Also did you try accessing contract via interface generated by code generator?Here is the full example code to check token balance which fails
import 'package:flutter/material.dart'; import 'package:webthree/webthree.dart'; import 'package:webthree/browser.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { String walletAddress = ''; String abi = '[{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]'; String contractAddress = '0xFf2bf3558421d4D340A3c6bEf738E92113Ed31f2'; // monk contract @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ walletAddress.isNotEmpty ? Text( 'Wallet Address: $walletAddress', ) : ElevatedButton( onPressed: () { browserConnect(); }, child: Text('Browser Connect', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.normal))), SizedBox( height: 20, ), walletAddress.isNotEmpty ? ElevatedButton( onPressed: () { getTokenBalance(); }, child: Text('Get Token Balance', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.normal))) : Container(), ], )), ); } browserConnect() async { final accs = await window.ethereum!.requestAccount(); walletAddress = accs.address.hex; setState(() {}); } getTokenBalance() async { DeployedContract deployedContractObj = DeployedContract( ContractAbi.fromJson(abi, 'MONK'), EthereumAddress.fromHex(contractAddress)); final client = Web3Client.custom(window.ethereum!.asRpcService()); await client.call( sender: EthereumAddress.fromHex(walletAddress), contract: deployedContractObj, function: deployedContractObj.function('balanceOf'), params: [ EthereumAddress.fromHex(walletAddress), ]).then((response) async { debugPrint('Response....$response'); }).catchError((onError, trace) { ScaffoldMessenger.of(context) .showSnackBar(new SnackBar(content: Text('$onError'))); debugPrint('Error....$onError'); debugPrint('Trace....$trace'); }); } }``` dependencies webthree: ^2.5.6+1Reacted by makinghappen@kaumudpa I have the same problem may be anybody found solution for it
@nemoRevers @kaumudpa are you sure the contract exists on the chain you are calling it?
Hi,
Please check this issue simolus3/web3dart#59 , This issue is observed in webthree aswell.
Any help or light on its resolution will be appriciated.