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

Invalid project token on Query 2 #4

Closed
tysun opened this issue Jan 13, 2022 · 1 comment
Closed

Invalid project token on Query 2 #4

tysun opened this issue Jan 13, 2022 · 1 comment

Comments

@tysun
Copy link

tysun commented Jan 13, 2022

The address data is good. print("Address data: \(r), \(r.address), \(r.txCount), \(r.sentSum)").

Since the first query passes, I'm guessing that the environment variable for my project id (API Key) is set correctly in the target's scheme.
However, during Query 2 I get:

Error getting an address: errorStatus(403, BlockfrostSwiftSDK.Status(statusCode: Optional(403), error: Optional("Forbidden"), message: Optional("Invalid project token."))

Just to be clear, in the Blockfrost SDK docs the API Key and product id are the same string value correct? Docs say, "project_id token is automatically generated for each project."

Also, I'm using the address given in the sample.
"addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y"

If I want to switch to a testnet I only need to change:

  • The project id (API Key)
  • The address to a testnet address i.e. [addr_test1vz95zjvtwm..]
  • The configuration to BlockfrostConfig.testnetDefault()

Is that correct?

Do you have a list of demo mainnet and testnet address we can use? I know we can just use an explorer to use any live mainnet address but what about testnet addresses?
These two where in your docs.
"addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y"

"addr_test1vz95zjvtwm9u9mc83uzsfj55tzwf99fgeyt3gmwm9gdw2xgwrvsa5"

 let api = CardanoAddressesAPI()
    _ = api.getAddressDetails(address: exampleAddr) { resp in
        switch (resp) {
        case let .failure(err):
            print("Error getting an address: \(self.exampleAddr): \(err)")
            break
        case let .success(r):
            print("Address data: \(r), \(r.address), \(r.txCount), \(r.sentSum)")
            print("JSON-encoded: \(String(data: (try? CodableHelper.encode(r).get()) ?? Data(), encoding: .utf8) ?? "-")")
            break
        }
        group.leave()
    }

    // Wait for async to complete
    group.wait()

    // Explicit configuration
    let config = BlockfrostConfig.mainnetDefault().clone()
    
    // Project id (API Key) here
    config.projectId = "BF_MAINNET_PROJECT_ID"
    config.apiResponseQueue = .global()
    group.enter()

    print("\n\nQuery 2: invalid project ID")
    let api2 = CardanoAddressesAPI(config: config)
    _ = api2.getAddressDetails(address: exampleAddr) { resp in
        switch (resp) {
        case let .failure(err):
            print("Error getting an address: \(err)")
            break
        case let .success(r):
            print("Address data: \(r)")
            break
        }
        group.leave()
    }
@ph4r05
Copy link
Collaborator

ph4r05 commented Jan 19, 2022

@tysun if you refer to the Example application, it is a correct behaviour.

We set incorrect project id to demonstrate SDK behaviour when project ID is not set

config.projectId = "non-existent"  // your project id here

Just to be clear, in the Blockfrost SDK docs the API Key and product id are the same string value correct? Docs say, "project_id token is automatically generated for each project."

Yes, API key and project_id are the same values. You have to obtain project_id at https://blockfrost.io

Do you have a list of demo mainnet and testnet address we can use?
You can use addresses from tests or use block explorer.

Ad testnet switch:
correct, use appropriate project_id, set it to the config or set environment variable BF_TESTNET_PROJECT_ID.

@ph4r05 ph4r05 closed this as completed Jan 19, 2022
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

2 participants