web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array<Any> but found a dictionary instead.", underlyingError: nil))

Open rachkumar opened this issue 4 years ago • 5 comments

Hi am using pod pod 'web3swift'

I have to send a amount from one ETH to another..please help to sort out... What I have tried: let web3Main = Web3.InfuraRopstenWeb3()

    do {
       let value: String = "0.1" // In Ether
       let walletAddress = EthereumAddress("xxxxxxxx")! // Your wallet address
       let toAddress = EthereumAddress("yyyyyyyyyy")!
       let contract = web3Main.contract(Web3.Utils.coldWalletABI, at: toAddress, abiVersion: 2)!
       let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
       var options = TransactionOptions.defaultOptions
       options.value = amount
       options.from = walletAddress
       options.gasPrice = .automatic
       options.gasLimit = .automatic
       print("oprions", options)
       let intermediateSend = try web3Main.eth.sendETH(to: toAddress, amount: amount!)._rlmInferWrappedType()
        let transaction = try intermediateSend.send(password: "", transactionOptions: options)
        print("transaction result", transaction.transaction)
        print("transaction result", transaction.transaction.hash)
        print("transaction result", transaction.transaction.txid)

    } catch(let err) {
        print("dbheb", err)
    }
        
}

Am getting error as: typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array<Any> but found a dictionary instead.", underlyingError: nil))

Please help to sort out

rachkumar avatar Mar 30 '20 15:03 rachkumar

Yes, I encountered the same problem, I opened two issues before, but was transferred to #239, and then # 239 closed, but my problem is still not resolved

haizhiwen avatar May 06 '20 06:05 haizhiwen

I don't know if this is still a thing but I had the same problem and used for my web3 instance my own endnote from infura.

let endpoint = URL(string: "your infura endpoint from your project") let web3 = Web3(url: endpoint!)

manuG420 avatar Aug 10 '20 15:08 manuG420

@manuG420 is correct check your web3 endpoint instance. I was using let web3 = try Web3.InfuraRinkebyWeb3() watch caused this error. The fix is to use your infura project endpoint (Project ID).

     let endpoint = URL(string: "<Your Infura Endpoint>")!
     let web3 = try Web3.new(endpoint)

When it come to debugging this error is caused by trying to decoding a Dictionary as an Array. Ends up being the data you received is an error message from the rpc server and does not conform to an array of JSONRPCresponse just a single instances.

The code below is from Web3+JSONRPC.swift lines 233-244 where the error is thrown. I modified it to help debug, as you can see from the output project ID is required is given in the response. To help others with this error I will give you my code used to debug.

Modified for debugging

/// JSON RPC batch response structure for serialization and deserialization purposes.
public struct JSONRPCresponseBatch: Decodable {
    var responses: [JSONRPCresponse]
    
    public init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        ///  Decode into a single JSONRPCresponse
        let responses = try container.decode(JSONRPCresponse.self) // throws here
        print("Successful \(responses)") /// print response
        /// Satisfy variable type Array
        self.responses = [responses] 
    }
}

OUTPUT

Successful JSONRPCresponse(id: 0, jsonrpc: "2.0", result: nil, error: Optional(Web3swift.JSONRPCresponse.ErrorMessage(code: -32600, message: "project ID is required")), message: nil, decodableTypes: [Swift.Array<Web3swift.EventLog>, Swift.Array<Web3swift.TransactionDetails>, Swift.Array<Web3swift.TransactionReceipt>, Swift.Array<Web3swift.Block>, Swift.Array<Swift.String>, Swift.Array<Swift.Int>, Swift.Array<Swift.Bool>, Web3swift.EventLog, Web3swift.TransactionDetails, Web3swift.TransactionReceipt, Web3swift.Block, Swift.String, Swift.Int, Swift.Bool, Swift.Dictionary<Swift.String, Swift.String>, Swift.Dictionary<Swift.String, Swift.Int>, Swift.Dictionary<Swift.String, Swift.Dictionary<Swift.String, Swift.Dictionary<Swift.String, Swift.Array<Swift.String>>>>])

MitchTODO avatar Jan 26 '21 01:01 MitchTODO

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 30.0 BUSD (30.0 USD @ $1.0/BUSD) attached to it.

gitcoinbot avatar Sep 13 '21 21:09 gitcoinbot

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 265 years, 2 months from now. Please review their action plans below:

1) nomebahi has started work.

I am trying and I hope solve it

Learn more on the Gitcoin Issue Details page.

gitcoinbot avatar Sep 14 '21 03:09 gitcoinbot

ErrorInvalid request. Error code: -32600. cannot extract signature

huqian1 avatar Nov 16 '23 08:11 huqian1

ErrorInvalid request. Error code: -32600. cannot extract signature

The library was completely rebuilt from that time, I strongly suggest you to raise a new issue rather than waiting any helpful answer here.

yaroslavyaroslav avatar Nov 16 '23 11:11 yaroslavyaroslav