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.
Install the Memecoin SDK and required peer dependencies:
yarn add @memecoin/sdkor
bun add @memecoin/sdkYou'll also need the following peer dependencies:
yarn add react react-dom @tanstack/react-query wagmi viemTo 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
})The SDK provides methods for accessing coin information, estimating and executing trades, and creating or launching tokens.
const coin = await sdk.getCoin(1) // Fetch by coin IDconst trendingCoins = await sdk.getTrending()Estimate the amount of tokens received from a buy order:
const amountOut = await sdk.estimateBuy({
coin,
using: 'eth',
amountIn: BigInt(10000000000000000)
})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 the amount of ETH received from a sell order:
const amountOut = await sdk.estimateSell({
coin,
using: 'eth',
amountIn: BigInt(50000000000000000)
})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 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'
})For React applications, the SDK can be integrated using the MemecoinProvider context. This provides easy access to the SDK methods throughout the component tree.
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>
);
}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>;
}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>;
}The SDK includes vitest tests to validate its functionality. Each test is configured with specific conditions and uses mock data.
Fetches a coin by its ID or Ethereum address.
Retrieves a list of trending Memecoins.
Estimates the token amount received for a given ETH input.
Executes a buy transaction on either Uniswap or the Memecoin pool.
Estimates the ETH amount received for a given token input.
Executes a sell transaction on either Uniswap or the Memecoin pool.
Generates a new Memecoin based on a given prompt.
Launches a newly generated Memecoin with specified properties.
To link locally and test
- install yalc
npm install -g yalc- build and publish the local package
bun run build
yalc publish- in the project you want to test against, link the local package
yalc add @memecoin/sdk
bun install- if you make changes to the local package, run
yalc publishagain
yalc publish --pushinstall dependencies
bun install