The trading instructions for buy and sell (but not mint) are directly available on-chain via the Moonshot Smart Contract.
Overview
The Moonshot SDK for EVM provides the following functions for Base and Abstract chains:
Minting of a token
Prepare and submit transactions
Upload all assets
Buy an initial amount of the tokens you minted
Get price of the token / position on bonding curve
Calculate collateral/token in and out
Generate buy and sell transactions (both exact in and out)
Set the slippage amount
Installation
Install the using npm or yarn
Copy
npm i @wen-moon-ser/moonshot-sdk-evm
# or
yarn add @wen-moon-ser/moonshot-sdk-evm
Initializing Moonshot
To initialize the Moonshot SDK, you need to create an instance of the Moonshot class. Before instantiating the Moonshot class, define your rpcUrl and signer.
Public endpoints for rpcUrl on Base
Public endpoints for rpcUrl on Abstract
Parameters of the Moonshot class
environment : You can initialize the environment for either mainnet or devnet
For Mainnet, use Environment.MAINNET
For Devnet, use Environemnt.TESTNET
signer : generated through your private key and rpcUrl
network : For selecting which chain you want to connect on
For Base, leave this parameter as empty (as in the example below)
For Abstract, use Network.ASBTRACT
import { Wallet } from 'ethers';
import { JsonRpcProvider } from 'ethers';
import { Moonshot, Token, FixedSide, Environment } from '@wen-moon-ser/moonshot-sdk-evm';
export const buyTx = async (): Promise<void> => {
console.log('--- Buying token example ---');
const rpcUrl = 'https://base-sepolia.gateway.tenderly.co';
const provider = new JsonRpcProvider(rpcUrl);
const signer = new Wallet('private key', provider);
const moonshot = new Moonshot({
signer: signer,
env: Environment.TESTNET,
// Currently supporting Base and Abstract (network :Network.ABSTRACT). Leave it empty for Base
});