npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@memecoin/sdk

v0.0.8

Published

The **Memecoin SDK** provides a powerful interface for interacting with Memecoin smart contracts, accessing token data, and executing token trades. Designed with flexibility in mind, the SDK can be used both in standalone applications and within React pro

Downloads

481

Readme

Memecoin SDK Documentation

The Memecoin SDK provides a powerful interface for interacting with Memecoin smart contracts, accessing token data, and executing token trades. Designed with flexibility in mind, the SDK can be used both in standalone applications and within React projects.

Installation

Install the Memecoin SDK and required peer dependencies:

yarn add @memecoin/sdk

or

bun add @memecoin/sdk

You'll also need the following peer dependencies:

yarn add react react-dom @tanstack/react-query wagmi viem

Quick Start

To initialize and configure the SDK, create a new MemecoinSDK instance:

import { MemecoinSDK } from '@memecoin/sdk'
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const sdk = new MemecoinSDK({
  rpcUrl: 'https://base-mainnet.g.alchemy.com/v2/API_KEY',
  privateKey: PRIVATE_KEY // Optional, only needed for write operations
})

Core Methods

The SDK provides methods for accessing coin information, estimating and executing trades, and creating or launching tokens.

Get Coin Information

const coin = await sdk.getCoin(1) // Fetch by coin ID

Get Trending Coins

const trendingCoins = await sdk.getTrending()

Estimate Buy

Estimate the amount of tokens received from a buy order:

const amountOut = await sdk.estimateBuy({
  coin,
  using: 'eth',
  amountIn: BigInt(10000000000000000)
})

Buy Tokens

Execute a buy transaction for a specific coin:

const transactionHash = await sdk.buy({
  coin,
  using: 'eth',
  amountIn: BigInt(10000000000000000),
  slippage: 5 // Optional, 5% slippage
})

Estimate Sell

Estimate the amount of ETH received from a sell order:

const amountOut = await sdk.estimateSell({
  coin,
  using: 'eth',
  amountIn: BigInt(50000000000000000)
})

Sell Tokens

Execute a sell transaction for a specific coin:

const transactionHash = await sdk.sell({
  coin,
  using: 'eth',
  amountIn: BigInt(50000000000000000),
  slippage: 5 // Optional, 5% slippage
})

Launch a Coin

Launch a newly generated token:

const { contractAddress, txHash } = await sdk.launch({
  name: 'New Meme',
  ticker: 'NMEME',
  antiSnipeAmount: BigInt(1000000000000000),
  image: 'https://example.com/image.png',
  website: 'https://example.com'
})

React Integration with MemecoinProvider

For React applications, the SDK can be integrated using the MemecoinProvider context. This provides easy access to the SDK methods throughout the component tree.

Provider Setup

In your root component:

import { MemecoinProvider } from '@memecoin/sdk';
import { WagmiConfig } from 'wagmi';
import { useMemo } from 'react';

const rpcUrl = 'https://base-mainnet.g.alchemy.com/v2/demo';

function App({ children }) {
  return (
    <MemecoinProvider rpcUrl={rpcUrl}>
      {children}
    </MemecoinProvider>
  );
}

Accessing SDK Methods

Inside any component, you can access SDK methods using the useMemecoin hook:

import { useMemecoin } from '@memecoin/sdk';

function CoinInfo() {
  const { getCoin, getTrending } = useMemecoin();

  useEffect(() => {
    async function fetchCoin() {
      const coin = await getCoin(1);
      console.log('Fetched coin:', coin);
    }

    fetchCoin();
  }, [getCoin]);

  return <div>Check console for coin data</div>;
}

Example: Buying a Coin

function BuyCoin({ coinId }) {
  const { getCoin, buy } = useMemecoin();

  const handleBuy = async () => {
    const coin = await getCoin(coinId);
    const transactionHash = await buy({
      coin,
      amountIn: BigInt(10000000000000000),
      amountOut: BigInt(50000000000000000)
    });
    console.log('Transaction Hash:', transactionHash);
  };

  return <button onClick={handleBuy}>Buy Coin</button>;
}

Testing

The SDK includes vitest tests to validate its functionality. Each test is configured with specific conditions and uses mock data.

API Reference

getCoin(id: EthAddress | number): Promise<HydratedCoin>

Fetches a coin by its ID or Ethereum address.

getTrending(): Promise<HydratedCoin[]>

Retrieves a list of trending Memecoins.

estimateBuy(params: EstimateTradeParams): Promise<bigint>

Estimates the token amount received for a given ETH input.

buy(params: TradeBuyParams): Promise<HexString>

Executes a buy transaction on either Uniswap or the Memecoin pool.

estimateSell(params: EstimateTradeParams): Promise<bigint>

Estimates the ETH amount received for a given token input.

sell(params: TradeSellParams): Promise<HexString>

Executes a sell transaction on either Uniswap or the Memecoin pool.

generateCoin(params: GenerateCoinParams): Promise<GenerateMemecoinFromPhraseResponse>

Generates a new Memecoin based on a given prompt.

launch(params: LaunchCoinParams): Promise<[EthAddress, HexString]>

Launches a newly generated Memecoin with specified properties.


Local testing

To link locally and test

  1. install yalc
npm install -g yalc
  1. build and publish the local package
bun run build
yalc publish
  1. in the project you want to test against, link the local package
yalc add @memecoin/sdk
bun install
  1. if you make changes to the local package, run yalc publish again
yalc publish --push

install dependencies

bun install