xclud / web3dart

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

Error while calling sendTransaction method -> String' is not a subtype of type 'List<dynamic>' of 'data' #78

Open rahulrmishra opened 1 year ago

rahulrmishra commented 1 year ago

This is my abi json file

[
  {
    "inputs": [
      {
        "components": [
          {
            "internalType": "address",
            "name": "nftSigner",
            "type": "address"
          }
        ],
        "internalType": "struct TradeLib.FinalizePurchase",
        "name": "data",
        "type": "tuple"
      }
    ],
    "name": "purchase",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
  ]

I'm calling a smart contraction method

      Transaction transaction = Transaction.callContract(
        contract: contract,
        function: contract.function('purchase'),
        parameters: [purchaseModel.nftSigner],
        from: EthereumAddress.fromHex(wallet.session.accounts[0]),

      );

 web3client.sendTransaction(
        WalletConnectEthereumCredentials(provider: provider),
        transaction,
        chainId: chainId,
      );

I'm getting error ->

Error type 'String' is not a subtype of type 'List<dynamic>' of 'data'
I/flutter (13485): #0      TupleType.encode (package:web3dart/src/contracts/abi/tuple.dart)
I/flutter (13485): #1      TupleType.encode (package:web3dart/src/contracts/abi/tuple.dart:68:14)
I/flutter (13485): #2      ContractFunction.encodeCall (package:web3dart/src/contracts/abi/abi.dart:255:10)
I/flutter (13485): #3      new Transaction.callContract (package:web3dart/src/core/transaction.dart:29:25)
MahmoudKEA commented 1 year ago

I see you are sending one parameter, while on ABI it asking for two parameters! Check your parameters and make sure your data type is right

reasje commented 4 months ago

@MahmoudKEA Are you sure? Because the ABI is defining only one input and that is of type struct TradeLib.FinalizePurchase which has only one property, I think that is what is causing the problem, Can you guide on how we can encode solidity structs in Flutter side?

reasje commented 4 months ago

@rahulrmishra Try to put the purchaseModel.nftSigner inside another braces : parameters: [[purchaseModel.nftSigner]], First list for parameters, second list for Solidity struct, Looks like Solidity structs are passed as list for encoding, And their properties are the items in this list (Priority should be important).