Lighthouse
  • 👋Introduction
  • Quick Start
  • How To
    • 🔑Create an API Key
    • 🔼Upload Data
      • 📁File
      • 🔤Text/JSON
      • 🔀Buffer
    • 🔒Upload Encrypted Data
      • 📁File
      • 🔤Text/JSON
      • 🔐Encryption Authentication
        • 📝Method 1: Signed Message
        • ⚕️Method 2: JWT
        • 📲Method 3: Passkey
    • Encryption Features
      • 👯Share File
      • ❌Revoke Access
      • 🔑Check Access Conditions
      • 🚪Token Gating
      • Chains Supported
      • 📃Access Control Conditions
      • 🔓Decrypt File
        • 🌐Browser Decrypt File
        • 💻NodeJS Decrypt File
      • 🚪Access control with zkTLS
      • 👬Account Delegation Tutorial
    • 📂List Files
    • 💁File Info
    • 💰Get Balance
    • 🔁Retrieve File
    • 💾Check for Filecoin Deals
    • 🔄IPNS - Handle Mutable Data
    • 📦Migrate Files
    • 📌Pin CID
    • 💸Pay per use
    • Resize Image
    • 💻Use CLI Tools
  • zkTLS
  • 🤝Account Delegation
  • 💾Filecoin First
    • Usage
    • 💰Pay Per Deal
  • Tutorials
    • 💸Pay to View Application
    • Use Python SDK
    • 📝Update Content with Lighthouse IPNS
    • 📹Add Video Player in UI
    • ✅Document Verification with PoDSI
    • 🎨Minting NFTs on EVM Chains
    • 🪙Minting NFTs on Solana
    • 👩‍💻Programmable Storage with Lighthouse SDK and Filecoin
    • 🔐Secure File Sharing
    • Upload Encrypted Files
    • 📄Token Gating and Custom Contract
    • 🔑Token Gating NFTs
    • 🏖️Pushing File Metadata Onchain
    • Use Radix Wallet on Lighthouse Filesdapp
  • Concepts
    • Glossary
    • IPFS CID Transition to v1
  • Support
    • 📞Contact
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. How To

Create an API Key

PreviousQuick StartNextUpload Data

Last updated 1 year ago

Was this helpful?

An API key is required to use Lighthouse, it can be generated using (check for more detail), CLI, and SDK. Refer to the given code examples to generate an API key based on your preferred environment.

In general, to create an API key there are two steps involved: 1. The user requests an authentication message from the message API. 2. The user signs the auth message to get the API key.

import axios from 'axios'
import { ethers } from 'ethers'
import lighthouse from '@lighthouse-web3/sdk'

const signAuthMessage = async(privateKey, verificationMessage) =>{
  const signer = new ethers.Wallet(privateKey)
  const signedMessage = await signer.signMessage(verificationMessage)
  return(signedMessage)
}

const getApiKey = async() =>{
  const wallet = {
    publicKey: 'YOUR_PUBLIC_KEY', // Ex: '0xEaF4E24ffC1A2f53c07839a74966A6611b8Cb8A1'
    privateKey: 'WALLET_PRIVATE_KEY'
  }
  const verificationMessage = (
    await axios.get(
        `https://api.lighthouse.storage/api/auth/get_message?publicKey=${wallet.publicKey}`
    )
  ).data
  const signedMessage = await signAuthMessage(wallet.privateKey, verificationMessage)
  const response = await lighthouse.getApiKey(wallet.publicKey, signedMessage)
  console.log(response)
}

getApiKey()

First, we need to get an authentication message that should be signed in order to generate an API key

curl https://api.lighthouse.storage/api/auth/get_message?publicKey=<publicKey>

This will send a message(string) in response that has to be signed by the user, the signature will be required to generate the API key

curl -X POST -d '{"publicKey": "value1", "signedMessage": "value2", "keyName": "value3"}' https://api.lighthouse.storage/api/auth/create_api_key

Before generating the API key using CLI make sure there is a wallet created or an existing wallet is imported in CLI. To check your wallet use the following command

lighthouse-web3 wallet
#Returns
#Public Key: 0x92a605b54a7F3171aF7D093d8CeD874236ea96A5
#Network: polygon

If there is no wallet, create one or import one using

lighthouse-web3 create-wallet

lighthouse-web3 import-wallet --key <private_key>

Now run the following command to create API key

lighthouse-web3 api-key --new
🔑
Files Dapp UI
quick start