Get Started

Learn how to get set up and started with the Nebula API to successfully prepare and enable a connected user to sign a transfer .

Prerequisites

Before you begin, ensure you have the following:

  • A thirdweb account
  • A blockchain wallet for executing transactions
  • Node.js and npm or yarn installed on your system

Obtain Client ID & Secret Key

  • Create project

    Navigate to the projects dashboard and create a new project.

    Create a new project
  • Obtain keys

    Setup your project and obtain your client ID and secret key. Please note your secret key somewhere safe as it is not recoverable.

    Obtain keys

Setup API (TypeScript SDK)

  • Install SDK

    Install the TypeScript SDK

    npm install thirdweb
  • Environment Variables

    Setup environmental variables.

    THIRDWEB_SECRET_KEY = your_thirdweb_secret_key;
    EOA_PRIVATE_KEY = your_wallet_private_key;
  • Import Libraries

    Import required libraries from thirdweb.

    import {
    createThirdwebClient,
    prepareTransaction,
    sendTransaction,
    privateKeyToAccount,
    } from "thirdweb";
  • Create Function to Handle Response

    This function processes the API's response and executes blockchain transactions.

    async function handleNebulaResponse(response) {
    const client = createThirdwebClient({
    secretKey: process.env.THIRDWEB_SECRET_KEY,
    });
    const account = privateKeyToAccount({
    client,
    privateKey: process.env.EOA_PRIVATE_KEY,
    });
    if (response.actions && response.actions.length > 0) {
    const action = response.actions[0];
    const txData = JSON.parse(action.data);
    try {
    const transaction = prepareTransaction({
    to: txData.to,
    data: txData.data,
    value: BigInt(txData.value),
    chain: txData.chainId,
    client,
    });
    const result = await sendTransaction({
    transaction,
    account,
    });
    console.log("Transaction Successful:", result);
    return result;
    } catch (error) {
    console.error("Error executing transaction:", error);
    throw error;
    }
    }
    }
  • Call Nebula API

    Send a request to the Nebula API to interpret your natural language command and retrieve the transaction details.

    const response = await fetch("https://nebula-api.thirdweb.com/chat", {
    method: "POST",
    headers: {
    "Content-Type": "application/json",
    "x-secret-key": process.env.THIRDWEB_SECRET_KEY,
    },
    body: JSON.stringify({
    message: "send 0.001 ETH on Sepolia to vitalik.eth",
    execute_config: {
    mode: "client",
    signer_wallet_address: "0xYourWalletAddress",
    },
    }),
    });
    const data = await response.json();
    await handleNebulaResponse(data);
  • Example Response

    The response from the API will contain the transaction details.

    Transaction Successful: {
    transactionHash: "0x123abc...",
    blockNumber: 1234567,
    ...
    }
  • Congratulations! You have successfully set up the Nebula API and executed a transaction using the thirdweb SDK.

Additional Resources