EtherWalletKit icon indicating copy to clipboard operation
EtherWalletKit copied to clipboard

Support Infura V3

Open romain64 opened this issue 6 years ago • 0 comments

Great repo !

Infura no longer supports the old API, now we have to access through https://mainnet.infura.io/v3/<PROJECT_ID>

I updated the project accordingly with the following pieces of code and my Project ID obtained through Infura dashboard:

EtherWallet.swift private let web3Main = Web3.InfuraMainnetWeb3("<PROJECT ID>")

Web3.swift (unchanged)

public static func InfuraMainnetWeb3(accessToken: String? = nil) -> web3 {
        let infura = InfuraProvider(Networks.Mainnet, accessToken: accessToken)!
        return web3(provider: infura)
    }

Web3+Infura.swift

public class InfuraProvider: Web3HttpProvider {
    public init?(_ net:Networks, accessToken token: String? = nil, keystoreManager manager: KeystoreManager? = nil) {
        var requestURLstring = "https://" + net.name + ".infura.io/v3/"
        if token != nil {
            requestURLstring = requestURLstring + token!
        }
        let providerURL = URL(string: requestURLstring)
        super.init(providerURL!, network: net, keystoreManager: manager)
    }
...
}

Requesting the balance with EtherWallet.balance throws the following error.

EtherWalletTest[3957:62791] CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = htps;
    "r_Attributes" = 1;
    sdmn = "Project ID is required in the URL";
    srvr = "mainnet.infura.io";
    sync = syna;
}

It seems that the project ID is missing in the call, but printing requestURLstring shows the correct URL with the access token.

romain64 avatar Jun 21 '19 13:06 romain64