buy

Purchase tokens from the bonding curve during funding phase.

Function Signature

function buy(
    address tokenAddress,
    string memory referral
) external payable

Parameters

tokenAddress
address
required
Address of the token to purchase
referral
string
Referral code for tracking and rewards
value
uint256
required
Amount of ETH to spend (sent as msg.value)

Events Emitted

event TokenPriceUpdate(
    address indexed token,
    address indexed pair,
    TransactionType txType,
    TokenPriceData priceData,
    TransactionData txData,
    string referral
)

Example

import { ethers } from 'ethers'

const factory = new ethers.Contract(
  TOKEN_FACTORY_ADDRESS,
  FACTORY_ABI,
  signer
)

async function buyTokens(tokenAddress: string, ethAmount: string) {
  const quote = await factory.getQuoteBuy(
    tokenAddress,
    ethers.utils.parseEther(ethAmount)
  )
  
  console.log(`Expected tokens: ${ethers.utils.formatEther(quote)}`)
  
  const tx = await factory.buy(
    tokenAddress,
    "REFERRAL_CODE",
    { value: ethers.utils.parseEther(ethAmount) }
  )
  
  await tx.wait()
}

sell

Sell tokens back to the bonding curve during funding phase.

Function Signature

function sell(
    address tokenAddress,
    uint256 amount,
    string memory referral
) external payable

Parameters

tokenAddress
address
required
Address of the token to sell
amount
uint256
required
Number of tokens to sell
referral
string
Referral code for tracking

Example

async function sellTokens(
  tokenAddress: string, 
  tokenAmount: string
) {
  const token = new ethers.Contract(
    tokenAddress,
    ERC20_ABI,
    signer
  )
  
  const amount = ethers.utils.parseEther(tokenAmount)
  
  const approveTx = await token.approve(
    TOKEN_FACTORY_ADDRESS,
    amount
  )
  await approveTx.wait()
  
  const quote = await factory.getQuoteSell(tokenAddress, amount)
  console.log(`Expected ETH: ${ethers.utils.formatEther(quote)}`)
  
  const tx = await factory.sell(
    tokenAddress,
    amount,
    "REFERRAL_CODE"
  )
  
  await tx.wait()
}

Error Handling