xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
170 stars 94 forks source link

Flutter web3dart error: Invalid argument: Instance of '_BigIntImpl' #132

Closed ganeshrajanbaboo closed 7 months ago

ganeshrajanbaboo commented 7 months ago

I am using web3dart with flutter for calling a smart contract view function from my android application. The call errs: Invalid argument: Instance of '_BigIntImpl'. The Solidity function requires String input like so:

function getIndividualCustomer(string memory _customer) public view returns (uint256 individualSellCount,
                                                                   uint256 individualSellAmount,
                                                                   uint256 individualBuyCount,
                                                                   uint256 individualBuyAmount,
                                                                   uint256 individualTransactionsPostEntry,
                                                                   uint256 individualAccruedDividend,
                                                                   address individualPayAddress) {
        return (customers[_customer].individualSellCount,
                customers[_customer].individualSellAmount,
                customers[_customer].individualBuyCount,
                customers[_customer].individualBuyAmount,
                customers[_customer].individualTransactionsPostEntry,
                customers[_customer].individualAccruedDividend,
                customers[_customer].individualPayAddress); 

    }

The function was tested fine from Remix. Now I am integrating it with my flutter application like so:

QuerySnapshot addressesSnapshot = await fetchDocuments();
    final contract = await fetchContract();
    for (var doc in addressesSnapshot.docs) {
      final id = (doc.data() as Map<String, dynamic>)['id'];
      final function = contract.function('getIndividualCustomer');
      List<dynamic> paramList = [];
      paramList.add(id);

      try {
        final result = await client.call(
          contract: contract,
          function: function,
          params: [id],
        );
        // Update the document with the returned data
        await doc.reference.update({
          'userSellCount': result[0],
          'userTotalSellAmount': result[1],
          'userBuyCount': result[2],
          'userTotalBuyAmount': result[3],
          'userTotalTransactionsPostEntry': result[4],
          'userTotalAccruedDividend': result[5],
          'userAccount': result[6],
        });
        debugPrint(
            'getIndividualCustomer call was successful for id: $id');
      } catch (e) {
        debugPrint(
            'getIndividualCustomer call failed for id: $id. Error: $e');
      }
    }
  }

The function is expected to retrieve details of input string memory _customer. In my case the input argument "id" is a UID of the form say, 9UlY5QpsmONa5bw1ZAV3yAdTwNL2. params of web3dart call is a List which take a list of input arguments. I have ensured that id is a string by checking its runtimeType and put it in a List. I have even tried with hardcoded literals. So my only argument is a string and nothing indicative of a BigInt.

However, every time I get the same error: Invalid argument: Instance of '_BigIntImpl'

Here is my contract Abi:

[
    {
        "anonymous": false,
        "inputs": [
            {
                "indexed": true,
                "internalType": "bytes32",
                "name": "transactionIdentifier",
                "type": "bytes32"
            },
            {
                "indexed": true,
                "internalType": "address",
                "name": "buyer",
                "type": "address"
            },
            {
                "indexed": true,
                "internalType": "address",
                "name": "seller",
                "type": "address"
            },
            {
                "indexed": false,
                "internalType": "address",
                "name": "signer",
                "type": "address"
            },
            {
                "indexed": false,
                "internalType": "uint256",
                "name": "transactionNumber",
                "type": "uint256"
            },
            {
                "indexed": false,
                "internalType": "uint256",
                "name": "transactionAmount",
                "type": "uint256"
            },
            {
                "indexed": false,
                "internalType": "uint256",
                "name": "depthFactor",
                "type": "uint256"
            },
            {
                "indexed": false,
                "internalType": "uint256",
                "name": "dispersedAmount",
                "type": "uint256"
            }
        ],
        "name": "EtherTransfersComplete",
        "type": "event"
    },
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "_corpus",
                "type": "uint256"
            }
        ],
        "name": "payCustomerDividends",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "payable",
        "type": "function"
    },
    {
        "inputs": [
            {
                "components": [
                    {
                        "internalType": "address",
                        "name": "buyer",
                        "type": "address"
                    },
                    {
                        "internalType": "address payable",
                        "name": "seller",
                        "type": "address"
                    },
                    {
                        "internalType": "uint256",
                        "name": "sellerReceivableAmount",
                        "type": "uint256"
                    },
                    {
                        "internalType": "string",
                        "name": "buyerUid",
                        "type": "string"
                    },
                    {
                        "internalType": "string",
                        "name": "sellerUid",
                        "type": "string"
                    }
                ],
                "internalType": "struct OnaughtEtherTransfer.TransactionInfo",
                "name": "transactionInfo",
                "type": "tuple"
            }
        ],
        "name": "payOnaughtSeller",
        "outputs": [],
        "stateMutability": "payable",
        "type": "function"
    },
    {
        "inputs": [],
        "stateMutability": "nonpayable",
        "type": "constructor"
    },
    {
        "stateMutability": "payable",
        "type": "fallback"
    },
    {
        "stateMutability": "payable",
        "type": "receive"
    },
    {
        "inputs": [
            {
                "internalType": "string",
                "name": "_customer",
                "type": "string"
            }
        ],
        "name": "getIndividualCustomer",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "individualSellCount",
                "type": "uint256"
            },
            {
                "internalType": "uint256",
                "name": "individualSellAmount",
                "type": "uint256"
            },
            {
                "internalType": "uint256",
                "name": "individualBuyCount",
                "type": "uint256"
            },
            {
                "internalType": "uint256",
                "name": "individualBuyAmount",
                "type": "uint256"
            },
            {
                "internalType": "uint256",
                "name": "individualTransactionsPostEntry",
                "type": "uint256"
            },
            {
                "internalType": "uint256",
                "name": "individualAccruedDividend",
                "type": "uint256"
            },
            {
                "internalType": "address",
                "name": "individualPayAddress",
                "type": "address"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "getTransactionsCount",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    }
]
ganeshrajanbaboo commented 7 months ago

Please ignore this question. The issue was not in the call. It was where I collected back the return value from the call and update my firestore database. It was a cast issue in the way I accepted them back.