2.21.20-beta.1 โ€ข Published 6 days ago

@sherrylinks/sdk v2.21.20-beta.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

Sherry SDK

npm version License: MIT TypeScript Tests GitHub Repo

๐ŸŒŸ Overview

Sherry SDK is a powerful toolkit for building interactive Web3 mini-apps that can be embedded within social media posts and platforms. The SDK enables developers to create rich, composable blockchain experiences without requiring users to leave their social media feed.

With Sherry, you can transform any post into an interactive dApp that allows users to swap tokens, vote on proposals, mint NFTs, sign transactions, and much more - all with built-in validation and a unified experience across chains.

โœจ Features

  • ๐Ÿ”— Multi-chain Support: Build once, deploy across Ethereum, Avalanche, Celo, and more
  • ๐Ÿงฉ Multiple Action Types:
    • Transfer Actions: Native token transfers with customizable UIs
    • Blockchain Actions: Smart contract interactions with rich parameter configuration
    • Dynamic Actions: Server-side logic with HTTP endpoints
    • Nested Action Flows: Interactive multi-step processes with conditional paths
  • ๐Ÿ“‹ Built-in Validation: Ensure your mini-apps are valid and well-formed before deployment
  • โšก Type Safety: Full TypeScript support with comprehensive type definitions
  • ๐Ÿ”„ Cross-chain Interactions: Enable transactions across multiple blockchains
  • ๐Ÿ“Š Rich Parameter Types: Select dropdowns, radio buttons, text inputs, and more
  • ๐Ÿ’ป Developer Tools: Built-in metadata analysis and debugging utilities
  • ๐Ÿ“ฑ Responsive Design: Mini-apps that work across all platforms and screen sizes

๐Ÿ“ฆ Installation

Install the SDK via npm or yarn:

# Using npm
npm install @sherrylinks/sdk

# Using yarn
yarn add @sherrylinks/sdk

๐Ÿš€ Quick Start

Basic Mini-App

import { createMetadata, Metadata } from '@sherrylinks/sdk';

// Create a simple token transfer metadata
const metadata: Metadata = {
  url: 'https://myapp.example',
  icon: 'https://example.com/icon.png',
  title: 'Send AVAX',
  description: 'Quick AVAX transfer',
  actions: [
    {
      label: 'Send 0.1 AVAX',
      description: 'Transfer 0.1 AVAX to recipient',
      to: '0x1234567890123456789012345678901234567890',
      amount: 0.1,
      chains: { source: 'avalanche' },
    },
  ],
};

// Validate and process metadata
const validatedMetadata = createMetadata(metadata);

Nested Action Flow

import { ActionFlow, createMetadata, Metadata } from '@sherrylinks/sdk';

// Create a flow with multiple steps and decision points
const swapFlow: ActionFlow = {
  type: 'flow',
  label: 'Token Swap',
  initialActionId: 'select-tokens',
  actions: [
    // Step 1: Select tokens and amount
    {
      id: 'select-tokens',
      type: 'http',
      label: 'Select Tokens',
      path: 'https://api.example.com/quote',
      params: [
        // Token selection parameters...
      ],
      nextActions: [{ actionId: 'review-quote' }],
    },

    // Step 2: Review and decide
    {
      id: 'review-quote',
      type: 'decision',
      label: 'Review Quote',
      title: 'Review Your Swap',
      options: [
        { label: 'Confirm', value: 'confirm', nextActionId: 'execute-swap' },
        { label: 'Cancel', value: 'cancel', nextActionId: 'cancelled' },
      ],
    },

    // Step 3: Execute swap
    {
      id: 'execute-swap',
      type: 'blockchain',
      label: 'Swap Tokens',
      address: '0xRouterAddress',
      // ... other blockchain action properties
      nextActions: [
        {
          actionId: 'success',
          conditions: [
            {
              field: 'lastResult.status',
              operator: 'eq',
              value: 'success',
            },
          ],
        },
        {
          actionId: 'failed',
          conditions: [
            {
              field: 'lastResult.status',
              operator: 'eq',
              value: 'error',
            },
          ],
        },
      ],
    },

    // Completion states
    {
      id: 'success',
      type: 'completion',
      label: 'Swap Complete',
      message: 'Your swap was successful!',
      status: 'success',
    },

    {
      id: 'failed',
      type: 'completion',
      label: 'Swap Failed',
      message: 'Your swap failed. Please try again.',
      status: 'error',
    },

    {
      id: 'cancelled',
      type: 'completion',
      label: 'Swap Cancelled',
      message: 'You cancelled the swap.',
      status: 'info',
    },
  ],
};

// Add to metadata
const flowMetadata: Metadata = {
  url: 'https://swap.example',
  icon: 'https://example.com/swap-icon.png',
  title: 'Advanced Token Swap',
  description: 'Swap tokens with our guided flow',
  actions: [swapFlow],
};

// Validate and process
const validatedFlow = createMetadata(flowMetadata);

๐Ÿงฉ Action Types

Blockchain Actions

Interact directly with smart contracts:

  • Call any contract function
  • Rich parameter configuration
  • Support for all Solidity types
  • Automatic gas estimation

Dynamic Actions

Server-side processing with HTTP endpoints:

  • Custom business logic
  • External API integrations
  • Real-time data processing
  • Complex calculations and optimizations

Nested Action Flows

Create multi-step interactive experiences:

  • Conditional branching
  • Decision points
  • Progress tracking
  • Completion states

๐ŸŒ Supported Chains

  • Ethereum Mainnet (ethereum)
  • Avalanche C-Chain (avalanche)
  • Avalanche Fuji Testnet (fuji)
  • Celo Mainnet (celo)
  • Celo Alfajores Testnet (alfajores)

More chains being added regularly

๐Ÿ“š Live Examples

Check out real working examples across different complexity levels:

View All Examples โ†’

๐Ÿ”ง Development Tools

Sherry Debugger

Test and validate your mini-apps during development:

  • Sherry Debugger - Interactive testing environment
  • Real-time validation
  • Parameter testing
  • JSON and TypeScript input support

Validation

{
  label: 'Approve Token',
  address: '0xContractAddress',
  abi: [...],  // Contract ABI
  functionName: 'approve',
  chains: { source: 'avalanche' },
  params: [
    {
      name: 'spender',
      label: 'Spender Address',
      type: 'address',
      required: true,
      value: '0xSpenderAddress',
      fixed: true  // User cannot change this value
    },
    {
      name: 'amount',
      label: 'Amount',
      type: 'number',
      required: true,
      min: 0
    }
  ]
}

Transfer Actions

Send native tokens or assets:

### HTTP Actions

- **๐ŸŽจ NFT Collections** - Let users mint NFTs directly from social posts
- **๐Ÿ”„ Token Swaps** - Enable DeFi trading without leaving social media
- **๐Ÿ—ณ๏ธ DAO Governance** - Streamline proposal voting and participation
- **๐Ÿ’ฐ Creator Economy** - Direct support and tipping mechanisms
- **๐Ÿฆ DeFi Integration** - Seamless access to lending, staking, and yield
  farming
- **๐ŸŽฎ Gaming** - In-game transactions and asset management
- **๐Ÿช Commerce** - Crypto payments and NFT marketplace integration

```typescript
{
  label: 'Submit Feedback',
  path: 'https://api.example.com/feedback',
  params: [
    {
      name: 'email',
      label: 'Email Address',
      type: 'email',
      required: true
    },
    {
      name: 'rating',
      label: 'Rating',
      type: 'select',
      required: true,
      options: [
        { label: 'โญ', value: 1 },
        { label: 'โญโญ', value: 2 },
        { label: 'โญโญโญ', value: 3 },
        { label: 'โญโญโญโญ', value: 4 },
        { label: 'โญโญโญโญโญ', value: 5 }
      ]
    },
    {
      name: 'comment',
      label: 'Comments',
      type: 'textarea',
      required: false
    }
  ]
}

Nested Action Flows

Create interactive, multi-step experiences with conditional paths:

{
  type: 'flow',
  label: 'DAO Voting',
  initialActionId: 'select-proposal',
  actions: [
    // Each step in the flow...
    {
      id: 'select-proposal',
      type: 'http',
      label: 'Select Proposal',
      // ... properties for this step
      nextActions: [
        { actionId: 'next-step' }
      ]
    },
    // Decision points with multiple paths
    {
      id: 'vote-decision',
      type: 'decision',
      label: 'Cast Vote',
      title: 'How do you vote?',
      options: [
        { label: 'Yes', value: true, nextActionId: 'submit-yes-vote' },
        { label: 'No', value: false, nextActionId: 'submit-no-vote' }
      ]
    },
    // Steps with conditional branching
    {
      id: 'submit-vote',
      type: 'blockchain',
      // ... properties
      nextActions: [
        {
          actionId: 'success-path',
          conditions: [{ field: 'lastResult.status', operator: 'eq', value: 'success' }]
        },
        {
          actionId: 'error-path',
          conditions: [{ field: 'lastResult.status', operator: 'eq', value: 'error' }]
        }
      ]
    },
    // Completion states
    {
      id: 'completion',
      type: 'completion',
      label: 'Vote Submitted',
      message: 'Your vote has been recorded!',
      status: 'success'
    }
  ]
}

๐Ÿ”ง Advanced Usage

Template Helpers

The SDK provides template helpers for common parameter types:

import { createParameter, PARAM_TEMPLATES } from '@sherrylinks/sdk';

// Create a parameter using a template
const emailParam = createParameter(PARAM_TEMPLATES.EMAIL, {
  name: 'email',
  label: 'Your Email',
  required: true,
});

// Create a select parameter with custom options
const tokenParam = createParameter(PARAM_TEMPLATES.TOKEN_SELECT, {
  name: 'token',
  label: 'Select Token',
  // Override default options
  options: [
    { label: 'USDC', value: 'usdc' },
    { label: 'DAI', value: 'dai' },
  ],
});

๐ŸŒ Supported Chains

  • Ethereum Mainnet (ethereum)
  • Avalanche C-Chain (avalanche)
  • Celo Mainnet (celo)
  • Avalanche Fuji Testnet (fuji)
  • Celo Alfajores Testnet (alfajores)

๐Ÿ“š Examples

The SDK includes several example mini-apps to help you get started:

Single Action Examples

  • Token Swap mini-app
  • NFT Marketplace mini-app
  • DAO Voting mini-app
  • Fundraising mini-app
  • Cross-chain Bridge mini-app

Flow Examples

  • User Onboarding Flow
  • DeFi Token Swap Flow
  • DAO Governance Flow

Check the src/examples directory for complete implementations.

๐Ÿ” Validation

The SDK provides extensive validation to ensure your mini-apps work correctly:

import { validateMetadata } from '@sherrylinks/sdk';

// Validate metadata
const validationResult = validateMetadata(myMetadata);

if (validationResult.isValid) {
  // Ready to use!
  console.log('Metadata is valid:', validationResult.type);
} else {
  // Handle validation errors
  console.error('Validation errors:', validationResult.errors);
}

๐Ÿ“– API Reference

Core Functions

  • createMetadata(metadata): Validates and processes metadata.
  • validateMetadata(input): Validates metadata and returns detailed results.

Type Guards

  • isBlockchainActionMetadata(action): Type guard for blockchain actions.
  • isTransferAction(action): Type guard for transfer actions.
  • isHttpAction(action): Type guard for HTTP actions.
  • isActionFlow(obj): Type guard for nested action flows.

Helper Functions

  • createParameter(template, customizations): Helper for parameter creation.
  • PARAM_TEMPLATES: Library of predefined parameter templates.

๐Ÿงช Development

# Install dependencies
yarn install

# Run tests
yarn test

# Run tests with coverage
yarn test --coverage

# Build the package
yarn build

# Start documentation server
cd docs && yarn install && yarn start

Browser Usage

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository.

  2. Clone your fork and create a new branch from develop:

    git clone https://github.com/YOUR_USERNAME/sherry-sdk.git
    cd sherry-sdk
    git switch -c feature/amazing-feature develop
  3. Commit your changes:

    # ...do your work...
    git add .
    git commit -m "feat: Add amazing feature"
  4. Push to your branch:

    git push origin feature/amazing-feature
  5. Open a Pull Request to the develop branch.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links

2.21.20-beta.1

6 days ago

2.21.19-beta.1

6 days ago

2.20.18-beta.1

9 days ago

2.20.17-beta.1

16 days ago

2.20.16-beta.1

16 days ago

2.20.15-beta.1

16 days ago

2.20.14-beta.1

21 days ago

2.20.13-beta.1

1 month ago

2.20.12-beta.1

1 month ago

2.20.11-beta.1

2 months ago

2.20.10-beta.1

2 months ago

2.20.9-beta.1

2 months ago

2.20.8-beta.1

2 months ago

2.20.7-beta.1

2 months ago

2.20.6-beta.1

2 months ago

2.20.7

2 months ago

2.20.6

2 months ago

2.20.5

2 months ago

2.20.5-beta.1

2 months ago

2.20.4-beta.1

2 months ago

2.19.4-beta.1

2 months ago

2.19.3-beta.1

2 months ago

1.19.3-beta.1

2 months ago

1.18.3-beta.1

2 months ago

1.17.3-beta.1

2 months ago

1.16.2-beta.1

2 months ago

1.15.2-beta.1

2 months ago

1.14.2-beta.1

2 months ago

1.13.2-beta.1

2 months ago

1.13.1-beta.1

2 months ago

1.12.1-beta.1

2 months ago

1.12.0-beta.1

2 months ago

1.11.0-beta.1

2 months ago

0.11.0-beta.1

2 months ago

0.10.0-beta.1

3 months ago

0.9.0-beta.1

3 months ago

0.8.0-beta.1

3 months ago

0.7.0-beta.1

4 months ago

0.6.0-beta.1

4 months ago

0.5.0-beta.1

4 months ago

0.4.0-beta.1

4 months ago

0.3.0-beta.1

4 months ago

0.2.0-beta.1

4 months ago

0.1.0-beta.1

4 months ago

0.16.0-alpha.1

5 months ago

0.15.0-alpha.1

5 months ago

0.14.0-alpha.1

5 months ago

0.13.0-alpha.1

5 months ago

0.12.0-alpha.1

5 months ago

0.11.0-alpha.1

5 months ago

0.10.0-alpha.1

5 months ago

0.9.0-alpha.1

5 months ago

0.8.0-alpha.1

5 months ago

0.7.0-alpha.1

6 months ago

0.6.0-alpha.1

6 months ago

0.5.0-alpha.1

6 months ago

0.4.0-alpha.1

6 months ago

0.3.0-alpha.1

6 months ago

0.2.18-alpha.1

7 months ago

0.1.18-alpha.1

7 months ago

0.0.18-alpha.1

7 months ago

0.0.17-alpha.1

7 months ago

0.0.16-alpha.1

7 months ago

0.0.15-alpha.1

7 months ago

0.0.14-alpha.1

7 months ago

0.0.13-alpha.1

7 months ago

0.0.12-alpha.1

7 months ago

0.0.11-alpha.1

7 months ago

0.0.10-alpha.1

7 months ago

0.0.9-alpha.1

7 months ago

0.0.8-alpha.1

7 months ago

0.0.7-alpha.1

7 months ago

0.0.6-alpha.1

7 months ago

0.0.5-alpha.1

7 months ago

0.0.4-alpha.1

7 months ago

0.0.3-alpha.1

7 months ago

0.0.2-alpha.1

7 months ago

0.0.1-alpha.1

7 months ago