|
| 1 | +--- |
| 2 | +title: Tempo API Quickstart |
| 3 | +description: How to get started building on Tempo and using the JSON-RPC API |
| 4 | +subtitle: How to get started building on Tempo and using the JSON-RPC API |
| 5 | +slug: reference/tempo-api-quickstart |
| 6 | +--- |
| 7 | + |
| 8 | +*To use the Tempo API you'll need to [create a free Alchemy account](https://dashboard.alchemy.com/signup) first!* |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +Tempo is a general-purpose blockchain optimized for payments. Tempo is designed to be a low-cost, high-throughput blockchain with user and developer features core to a modern payment system. |
| 13 | + |
| 14 | +## What is the Tempo API? |
| 15 | + |
| 16 | +The Tempo API allows interaction with the Tempo network through a set of JSON-RPC methods. Its design is familiar to developers who have worked with Ethereum's JSON-RPC APIs, making it intuitive and straightforward to use. |
| 17 | + |
| 18 | +## Getting Started Instructions |
| 19 | + |
| 20 | +### 1. Choose a Package Manager (npm or yarn) |
| 21 | + |
| 22 | +Select a package manager to manage your project's dependencies. Choose between `npm` and `yarn` based on your preference or project requirements. |
| 23 | + |
| 24 | +<CodeGroup> |
| 25 | + ```shell npm |
| 26 | + # Begin with npm by following the npm documentation |
| 27 | + # https://docs.npmjs.com/downloading-and-installing-node-js-and-npm |
| 28 | + ``` |
| 29 | + |
| 30 | + ```shell yarn |
| 31 | + # For yarn, refer to yarn's installation guide |
| 32 | + # https://classic.yarnpkg.com/lang/en/docs/install |
| 33 | + ``` |
| 34 | +</CodeGroup> |
| 35 | + |
| 36 | +### 2. Set Up Your Project |
| 37 | + |
| 38 | +Open your terminal and execute the following commands to create and initialize your project: |
| 39 | + |
| 40 | +<CodeGroup> |
| 41 | + ```shell npm |
| 42 | + mkdir tempo-api-quickstart |
| 43 | + cd tempo-api-quickstart |
| 44 | + npm init --yes |
| 45 | + ``` |
| 46 | + |
| 47 | + ```shell yarn |
| 48 | + mkdir tempo-api-quickstart |
| 49 | + cd tempo-api-quickstart |
| 50 | + yarn init --yes |
| 51 | + ``` |
| 52 | +</CodeGroup> |
| 53 | + |
| 54 | +This creates a new directory named `tempo-api-quickstart` and initializes a Node.js project within it. |
| 55 | + |
| 56 | +### 3. Make Your First Request |
| 57 | + |
| 58 | +Install Axios, a popular HTTP client, to make API requests: |
| 59 | + |
| 60 | +<CodeGroup> |
| 61 | + ```shell npm |
| 62 | + npm install axios |
| 63 | + ``` |
| 64 | + |
| 65 | + ```shell yarn |
| 66 | + yarn add axios |
| 67 | + ``` |
| 68 | +</CodeGroup> |
| 69 | + |
| 70 | +Create an `index.js` file in your project directory and paste the following code: |
| 71 | + |
| 72 | +<CodeGroup> |
| 73 | + ```javascript index.js |
| 74 | + const axios = require('axios'); |
| 75 | + |
| 76 | + const url = 'https://tempo-testnet.g.alchemy.com/v2/${your-api-key}'; |
| 77 | + |
| 78 | + const payload = { |
| 79 | + jsonrpc: '2.0', |
| 80 | + id: 1, |
| 81 | + method: 'eth_blockNumber', |
| 82 | + params: [] |
| 83 | + }; |
| 84 | + |
| 85 | + axios.post(url, payload) |
| 86 | + .then(response => { |
| 87 | + console.log('Latest Block:', response.data.result); |
| 88 | + }) |
| 89 | + .catch(error => { |
| 90 | + console.error(error); |
| 91 | + }); |
| 92 | + ``` |
| 93 | +</CodeGroup> |
| 94 | + |
| 95 | +Remember to replace `your-api-key` with your actual Alchemy API key that you can get from your [Alchemy dashboard](https://dashboard.alchemy.com/signup). |
| 96 | + |
| 97 | +### 4. Run Your Script |
| 98 | + |
| 99 | +Execute your script to make a request to the Tempo network: |
| 100 | + |
| 101 | +<CodeGroup> |
| 102 | + ```shell shell |
| 103 | + node index.js |
| 104 | + ``` |
| 105 | +</CodeGroup> |
| 106 | + |
| 107 | +You should see the latest block information from Tempo's network outputted to your console: |
| 108 | + |
| 109 | +<CodeGroup> |
| 110 | + ```shell shell |
| 111 | + Latest Block: 0x... |
| 112 | + ``` |
| 113 | +</CodeGroup> |
| 114 | + |
| 115 | +## Next Steps |
| 116 | + |
| 117 | +Congratulations! You've made your first request to the Tempo network. You can now explore the various JSON-RPC methods available on Tempo and start building your dApps on this innovative platform. |
0 commit comments