@0xsequence/sidekick-cli
v0.0.1
Published
Sidekick API CLI
Readme
Sidekick CLI
A powerful command-line tool for generating Fastify API endpoints from smart contract ABIs for Sequence Sidekick.
Features
- 🚀 Automatic API Generation: Generate complete Fastify API endpoints from any smart contract ABI
- 📝 Write Endpoints: Create transaction endpoints for state-changing functions
- 📖 Read Endpoints: Create query endpoints for view/pure functions
- 🔄 Function Overloading Support: Handle multiple functions with the same name
- 🎯 TypeScript Support: Full TypeScript type definitions and schemas
- 🔧 Customizable Output: Flexible output directory configuration
- 🛡️ Error Handling: Comprehensive error handling and logging
Installation
Global Installation (Published Package)
npm install -g @0xsequence/sidekick-cli
# or
pnpm install -g @0xsequence/sidekick-cli
# or
yarn install -g @0xsequence/sidekick-cliUsage Guide
sidekick-cli build-api \
--abi ./abis/erc20.json \
--output ./src/contract/extensionsThe CLI will automatically import the generated API routes into src/routes/index.ts in order to expose the endpoints to your Fastify app.
If no output directory is provided, the CLI will default to ./src/routes/contract/autogenerated.
If no contract name is provided, the CLI will automatically use the ABI file name.
If provided, --contract-name must match the ABI file name. (ex: ERC20.json -> ERC20)
Command Options
| Option | Required | Description | Default |
|--------|----------|-------------|---------|
| --abi <path> | ✅ | Path to the ABI JSON file | - |
| --contract-name <name> | ✅ | Name of the smart contract | - |
| --output <path> | ❌ | Output directory for generated files | ./generated |
Examples
Generate API for ERC20 Tokens
sidekick-cli build-api \
--abi ./abis/erc20.json \
--contract-name ERC20 \
--output ./api/contractsGenerate API for Custom Contracts
sidekick-cli build-api \
--abi ./contracts/MyNFT.json \
--contract-name MyNFT \
--output ./generated-apisGenerated Output Structure
The CLI generates a well-organized directory structure:
{output-directory}/
└── {contract-name}/
├── index.ts # Main registration file
├── read/ # Read-only function endpoints
│ ├── balanceOf.ts
│ ├── name.ts
│ └── symbol.ts
└── write/ # State-changing function endpoints
├── transfer.ts
├── approve.ts
└── mint.tsSupported ABI Types
The CLI automatically maps Solidity types to TypeScript types:
| Solidity Type | TypeScript Type | Notes |
|---------------|-----------------|-------|
| uint* | string | Converted to string for JSON compatibility |
| int* | string | Converted to string for JSON compatibility |
| address | string | Ethereum address as string |
| string | string | Direct mapping |
| bytes* | string | Hex-encoded bytes |
| bool | boolean | Boolean type |
| *[] | string[] | Arrays of any supported type |
Unsupported Parameter Types (WIP)
- Structs (tuple): A function like
function setUser(User memory _user)where User is a struct will not work. - Arrays of Structs (tuple[]): A function like
function addUsers(User[] memory _users)will not be supported. - Multi-dimensional Arrays: A function defined as
function setMatrix(uint256[][] memory _matrix)would have its parameter type incorrectly handled. - Fixed-Size Arrays: A function signature like
function setWhitelist(address[10] memory _addresses)will not be correctly processed.
Function Overloading
The CLI handles function overloading by appending numeric suffixes:
transfer(address,uint256)→transfer.tstransfer(address,uint256,bytes)→transfer_2.ts
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions, please open an issue on the GitHub repository.
