Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rachkumar opened this issue Mar 30, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@rachkumar
Copy link

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, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))

Please help to sort out

@haizhiwen
Copy link

haizhiwen commented May 6, 2020

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

@manuG420
Copy link
Contributor

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!)

@MitchTODO
Copy link

MitchTODO commented Jan 26, 2021

@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>>>>])

@skywinder skywinder added bug Something isn't working help wanted Extra attention is needed 💸 gitcoin-bounty Earn money by helping with this issue! labels Sep 13, 2021
@gitcoinbot
Copy link

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
Copy link

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.

@yaroslavyaroslav yaroslavyaroslav removed 💸 gitcoin-bounty Earn money by helping with this issue! help wanted Extra attention is needed labels Oct 23, 2022
@yaroslavyaroslav yaroslavyaroslav closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2022
@huqian1
Copy link

huqian1 commented Nov 16, 2023

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

@yaroslavyaroslav
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants