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
| Parameter | Type | Required | Description |
|---|---|---|---|
network | ShelbyNetwork | Yes | The Shelby network (e.g., Network.SHELBYNET) |
apiKey | string | Yes | Your Shelby API key |
gasStationApiKey | string | No | Gas 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
| Parameter | Type | Required | Description |
|---|---|---|---|
ethereumWallet | Wallet | Yes | An ethers.js Wallet instance |
domain | string | Yes | The dApp domain for address derivation |
scheme | string | No | URI 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:
| Method | Description |
|---|---|
upload | Upload a blob to Shelby |
download | Download a blob from Shelby |
fundAccountWithAPT | Fund an account with APT (gas fees) |
fundAccountWithShelbyUSD | Fund 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.