Ethereum Kit

Shelby Client

The main client for Ethereum-Shelby integration

The Shelby class is the main entry point for server-side Ethereum-Shelby integration. It extends the core ShelbyClient with Ethereum-specific functionality.

Import

import { Shelby, Network } from "@shelby-protocol/ethereum-kit/node";

Constructor

const shelbyClient = new Shelby({
  network: Network.SHELBYNET,
  apiKey: "AG-***",
  gasStationApiKey: "GS-***", // Optional
});

Parameters

ParameterTypeRequiredDescription
networkShelbyNetworkYesThe Shelby network (e.g., Network.SHELBYNET)
apiKeystringYesYour Shelby API key
gasStationApiKeystringNoGas Station API key for sponsored transactions

Methods

createStorageAccount

Creates a storage account from an ethers.js Wallet.

const storageAccount = shelbyClient.createStorageAccount(
  ethereumWallet,
  domain,
  scheme
);

Parameters

ParameterTypeRequiredDescription
ethereumWalletWalletYesAn ethers.js Wallet instance
domainstringYesThe dApp domain for address derivation
schemestringNoURI scheme (default: "https")

Returns

Returns a ShelbyStorageAccount instance that can be used as a signer.

Inherited Methods

The Shelby class inherits all methods from ShelbyClient:

MethodDescription
uploadUpload a blob to Shelby
downloadDownload a blob from Shelby
fundAccountWithAPTFund an account with APT (gas fees)
fundAccountWithShelbyUSDFund an account with ShelbyUSD (storage)

Complete Example

import { Shelby, Network } from "@shelby-protocol/ethereum-kit/node";
import { Wallet } from "ethers";

async function main() {
  // Initialize client
  const shelbyClient = new Shelby({
    network: Network.SHELBYNET,
    apiKey: process.env.SHELBY_API_KEY!,
  });

  // Create storage account from private key
  const ethereumWallet = new Wallet(process.env.ETHEREUM_PRIVATE_KEY!);
  const storageAccount = shelbyClient.createStorageAccount(
    ethereumWallet,
    "my-dapp.com"
  );

  console.log("Storage Account:", storageAccount.accountAddress.toString());

  // Fund the account
  await shelbyClient.fundAccountWithShelbyUSD({
    address: storageAccount.accountAddress,
    amount: 1_000_000,
  });

  await shelbyClient.fundAccountWithAPT({
    address: storageAccount.accountAddress,
    amount: 1_000_000,
  });

  // Upload a file
  const blobName = `hello-${Date.now()}.txt`;
  await shelbyClient.upload({
    blobData: new TextEncoder().encode("Hello, Shelby!"),
    signer: storageAccount,
    blobName,
    expirationMicros: Date.now() * 1000 + 86400000000,
  });

  console.log("Done! File available at:");
  console.log(
    `https://api.shelbynet.shelby.xyz/shelby/v1/blobs/${storageAccount.accountAddress}/${blobName}`
  );
}

main().catch(console.error);

Gas Station (Sponsored Transactions)

To sponsor gas fees for your users, provide a Gas Station API key:

const shelbyClient = new Shelby({
  network: Network.SHELBYNET,
  apiKey: "AG-***",
  gasStationApiKey: "GS-***",
});

With a Gas Station key configured, users don't need APT in their accounts for transaction fees.