Using API Keys
Create and authenticate with a traditional API Key on Space and Time!
Often developers prefer a simple, application centric authentication method such as an API Key. Fortunately, Space and Time makes it very easy to generate and manage API Keys using Space and Time Studio!
Let's Get Started!
To be able to validate your script, we'd ask that you generate a new file called Using_API_Keys.sh that you can commit to your branch of the SXT-Community/SXTAccreditation repo at the end of the activity.
Create a New API Key
Often developers prefer a simple, application centric authentication method such as an API Key. Fortunately, Space and Time makes it very easy to generate and manage API Keys using Space and Time Studio!
To Generate or Manage API Keys:
-
Navigate to Space and Time Studio, click on "Sign in" in the upper-right most corner, and login.
-
Click on "My Account" in the upper-right most corner (replaces "Sign in") and click on the "Permission and Keys" tab.
-
On that tab, you will see an API Key section. If you have no defined API Keys, the UI will display the "Create API Key" view:
-
To create a new API Key, simply add a note (to remind yourself where/how the key will be used) and click "Add"
Copy and save your API Key! It will never be shown again! If you forget to copy, you'll have to delete and re-create a new key.
Congrats! You've just created your first API Key!
If you have existing keys, you should see the "API Key" management view instead:
From here, you can see existing keys and delete keys (using the trash-can icon on the right).
What is the difference between API Keys are Access Tokens?
An ACCESS_TOKEN is the cryptographic session to the Space and Time decentralized network, meaning you're connected to the network directly.
An API key is managed by a Space and Time Gateway / Secrets Proxy, meaning it is authenticating to a near-chain auth server, instead of the decentralized network itself. This allows access to a good number of APIs, but not the full set available to a decentralized ACCESS_TOKEN.
You can however use your authenticated API Key to request a full network ACCESS_TOKEN, allowing your application access to the entire suite of decentralized network APIs using an API Key.
Run a Query with API Key
Let's run this fairly simple TPS comparative query for January, 2024 - first using the API Key directly, then again using the Decentralized Network.
Select 'SUI' as Name, count(*)/86400.00 as TPS from SUI.TRANSACTIONS
where time_stamp between '2024-01-01' and '2024-01-31'
union all
Select 'POLYGON' as Name, count(*)/86400.00 as TPS from POLYGON.TRANSACTIONS
where time_stamp between '2024-01-01' and '2024-01-31'
union all
Select 'ETHEREUM' as Name, count(*)/86400.00 as TPS from ETHEREUM.TRANSACTIONS
where time_stamp between '2024-01-01' and '2024-01-31'
Congrats! You just ran a query using your API Key!
Space and Time provides API calls that allow you to exchange your Secrets Proxy API_Key, UserName/Password, or active Space and Time Studio SessionID for a decentralized ACCESS_TOKEN. This in turn allows you to operate any API on the entire Space and Time network.
Get Credit:
You'll get credit for this activity if you:
- Create an API Key using Space and Time Studio
- Run the exact query above, using the Proxy SQL API (as shown above)
- Use your API_Key to create a new ACCESS_TOKEN
- Run the exact query above, using the Decentralized SQL API (as shown above)
- Commit your work file to the SXT-Community/SXTAccreditation repo
How should I commit my branch changes?
When you're complete with the activity, simply commit your changes to your branch of work, then push to the SXT-Community/SXTAccreditation repo. Many IDEs have automated processes to manage this for you, but to do this manually by opening a temrinal / WSL window, and typing:
If you get an error on line 5 saying, The current branch stephens_work has no upstream branch
, this is because Github doesn't know about your branch yet. Simply run the command the git tool recommends - it will look something like:
git push --set-upstream origin <your_branch>
When you're done for the day, head over to SXT-Community/SXTAccreditation/Pulls page on Github, and (if you're logged in) you'll see a message like:
Click on the button above to create a Pull Request, give us some feedback in the description, and click "Create Pull Request". Done!
Updated about 2 months ago