Skip to main content

🔑 Create an API Key

An API key is required to use Lighthouse IPFS Walrus. You can generate one from the Walrus Dashboard (see Quick Start), SDK, or API.

To create an API key, use your Sui address as the publicKey:

  1. Request an authentication message from the message API.
  2. Sign the auth message with your Sui wallet or keypair to get the API key.

import axios from 'axios'
import lighthouse from '@lighthouse-web3/sdk'
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'

const signAuthMessage = async (keypair, verificationMessage) => {
const message = new TextEncoder().encode(verificationMessage)
const { signature } = await keypair.signPersonalMessage(message)
return signature
}

const getApiKey = async () => {
const keypair = Ed25519Keypair.fromSecretKey('YOUR_SUI_PRIVATE_KEY')
const publicKey = keypair.toSuiAddress() // Ex: '0x8b2f...'

const verificationMessage = (
await axios.get(
`https://api.lighthouse.storage/api/auth/get_message?publicKey=${publicKey}`
)
).data

const signedMessage = await signAuthMessage(keypair, verificationMessage)
const response = await lighthouse.getApiKey(publicKey, signedMessage)
console.log(response)
}

getApiKey()
Browser wallet (Slush)

If you are signing in the browser, connect Slush (or another Sui wallet), fetch the verification message with your Sui address, then call signPersonalMessage on the connected wallet with the message bytes before calling lighthouse.getApiKey.