Sui API Quickstart

💡 Available only with Blast access

Introduction

The Sui API enables developers to interact with the Sui blockchain via a collection of JSON-RPC endpoints. With this API, you can query block and transaction data, interact with Move-based smart contracts, manage assets, and more.

Unlike Ethereum-based chains, Sui uses an object-centric data model, optimized for parallel execution and scalability. This quickstart will help you make your first request to the network.


What is the Sui Chain API?

The Sui Chain API allows developers to send queries and transactions to the Sui blockchain through a JSON-RPC interface. With Sui’s object-based architecture and horizontal scalability, developers benefit from high throughput and low-latency reads and writes.

Alchemy’s Sui API provides developers with consistent and performant access to:

  • Retrieving account and object data
  • Querying blocks, transactions, and events
  • Simulating and broadcasting transactions
  • Accessing Move smart contract modules and functions

Getting Started Instructions

1. Choose a Package Manager (npm or yarn)

Your first step involves selecting a package manager, which will be crucial for managing your project’s dependencies. The choice between npm and yarn depends on your personal preference or project requirements.

npmyarn
Begin with npm by following the npm documentation.For yarn, refer to yarn’s installation guide.

2. Set Up Your Project

To kickstart your project, open your terminal and execute the following commands:

mkdir sui-api-quickstart
cd sui-api-quickstart
npm init --yes

This creates a new directory named sui-api-quickstart and initializes a Node.js project within it.

3. Make Your First Request

Install Axios, a popular HTTP client, to make API requests:

bash
$npm install axios
># Or with yarn
># yarn add axios

Create an index.js file in your project directory and paste the following code:

javascript
1const axios = require('axios');
2
3const url = `https://sui-mainnet.alchemy-blast.com/v2/${yourAPIKey}`;
4
5const payload = {
6jsonrpc: '2.0',
7id: 1,
8method: 'sui_getLatestCheckpointSequenceNumber',
9params: []
10};
11
12axios.post(url, payload)
13.then(response => {
14console.log('Latest checkpoint sequence number:', response.data.result);
15})
16.catch(error => {
17console.error('Error fetching checkpoint:', error);
18});

Remember to replace yourAPIKey with your actual Alchemy API key that you can get from your Alchemy dashboard.

4. Run Your Script

To execute your script and make a request to the Sui App, run:

bash
$node index.js

You should see the latest checkpoint sequence number on Sui App outputted to your console:

Latest checkpoint sequence number: 1029433

Next Steps

Well done! You’ve just made your first request to the Sui App API. With this foundation, you can dive deeper into the array of JSON-RPC methods available on Sui App and start building your dApps on it!