web3swift
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))
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
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
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 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>>>>])
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.
- If you would like to work on this issue you can 'start work' on the Gitcoin Issue Details page.
- Want to chip in? Add your own contribution here.
- Questions? Checkout Gitcoin Help or the Gitcoin's Discord
- $5,620,469.27 more funded OSS Work available on the Gitcoin Issue Explorer
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.
ErrorInvalid request. Error code: -32600. cannot extract signature
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.