This template helps you develop Lit Actions with TypeScript support, SDK shimming, and automated IPFS deployment.
# Install dependencies
pnpm install
# Copy environment variables
cp .env.example .env
# Start development
pnpm run dev
lit-actions/
βββ actions/ # Built JS actions + IPFS hashes
β βββ hello-action.js
β βββ ipfs.json # IPFS deployment info
βββ shims/ # SDK shims
β βββ buffer.shim.js
βββ src/
β βββ actions/ # TypeScript action source
β β βββ hello-action.ts
β βββ global.d.ts # Global type definitions
β βββ index.ts # IPFS deployment script
βββ esbuild.js # Build configuration
βββ package.json
- Create a new action in
src/actions/
:
/// <reference path="../global.d.ts" />
const go = async () => {
// Get the token ID from public key
const tokenId = await Lit.Actions.pubkeyToTokenId({ publicKey });
// Sign data
const signature = await Lit.Actions.signEcdsa({
publicKey,
toSign,
sigName,
});
// Return response
Lit.Actions.setResponse({
response: JSON.stringify({ tokenId, signature }),
});
};
go();
- Create a shim in
shims/
:
// shims/my-sdk.shim.js
import { MySDK } from "my-sdk";
globalThis.MySDK = MySDK;
- Update global types in
src/global.d.ts
:
import { MySDK } from "my-sdk";
declare global {
// Add SDK to global scope
const MySDK: typeof MySDK;
// Add action parameters
const myParam: string;
}
- The shim will be automatically injected via esbuild:
// esbuild.js
const shimFiles = glob.sync("./shims/**/*.shim.js");
// ...
inject: shimFiles,
Required variables in .env
:
# Pinata IPFS Configuration
PINATA_JWT=<Your Pinata JWT>
PINATA_URL=<Your Pinata URL>
The validate-env
script will prompt for missing variables:
pnpm run predev
# Build actions
pnpm run build
# Deploy to IPFS
pnpm run start
This will:
- Compile TypeScript β JavaScript
- Bundle with dependencies
- Inject SDK shims
- Upload to IPFS via Pinata
- Save IPFS hashes to
actions/ipfs.json
/// <reference path="../global.d.ts" />
const go = async () => {
try {
console.log("Lit.Auth:", Lit.Auth);
// Convert public key to token ID
const tokenId = await Lit.Actions.pubkeyToTokenId({ publicKey });
console.log("tokenId:", tokenId);
// Get permitted auth methods
const permittedAuthMethods = await Lit.Actions.getPermittedAuthMethods({
tokenId,
});
console.log("permittedAuthMethods:", permittedAuthMethods);
// Sign with ECDSA
const signature = await Lit.Actions.signEcdsa({
publicKey,
toSign,
sigName,
});
// Set response
Lit.Actions.setResponse({
response: JSON.stringify({
tokenId,
signature,
permittedAuthMethods,
}),
});
} catch (error) {
console.error("Action failed:", error);
throw error;
}
};
go();
# Development
pnpm run dev # Build + start
pnpm run build # Build actions
pnpm run start # Deploy to IPFS
# Utilities
pnpm run lint # Fix code style
pnpm run predev # Validate env vars
The global.d.ts
file provides types for:
- Lit Actions API
- Global parameters
- SDK shims
- Buffer utilities
- Ethers.js integration
Actions are automatically deployed to IPFS with metadata saved to actions/ipfs.json
:
{
"hello-action.js": {
"IpfsHash": "Qm...",
"PinSize": 69804,
"Timestamp": "2025-01-03T08:55:32.951Z",
"Duration": 4.319
}
}
-
Type Safety
- Always reference
global.d.ts
- Define types for parameters
- Use TypeScript features
- Always reference
-
SDK Management
- Create minimal shims
- Document SDK versions
- Test SDK compatibility
-
Action Structure
- One action per file
- Clear async/await flow
- Proper error handling
-
Deployment
- Test locally first
- Verify IPFS uploads
- Keep actions small
MIT