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

Support Infura V3 #7

Open
romain64 opened this issue Jun 21, 2019 · 0 comments
Open

Support Infura V3 #7

romain64 opened this issue Jun 21, 2019 · 0 comments

Comments

@romain64
Copy link

romain64 commented Jun 21, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant