Skip to content

buy

Buys tokens from the bonding curve contract.

Usage

example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
 
await mintclub.network('ethereum').token('SYMBOL').buy({
	amount: wei(1, 18),
})

Return Value

Promise<TransactionReceipt>

Returns a promise that resolves to a TransactionReceipt object when the transaction is successful.

Parameters

amount

  • Type: bigint

The amount of tokens to buy from the bonding curve contract.

example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
 
await mintclub.network('ethereum').token('SYMBOL').buy({
	amount: wei(1, 18) 
})

recipient (optional)

  • Type: '0x${string}'
  • Default: signer address

The address to send the bought tokens to. If not provided, the tokens will be sent to the user's address.

example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
 
await mintclub.network('ethereum').token('SYMBOL').buy({
	amount: wei(1, 18),
	recipient: '0x1234567890123456789012345678901234567890'
})

slippage (optional)

  • Type: number
  • Default: 0
example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
 
await mintclub.network('ethereum').token('SYMBOL').buy({
	amount: wei(1, 18),
	slippage: 1 // 1%
})

allowanceAmount (optional)

  • Type: bigint
  • Default: MaxUint256

The amount of tokens to approve the bonding curve contract to use the asset's reserve token. If not provided, the SDK will automatically use MaxUint256 as the allowance amount.

example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
 
await mintclub.network('ethereum').token('SYMBOL').buy({
	amount: wei(1, 18),
	allowanceAmount: wei(1, 18) 
})

onAllowanceSignatureRequest (optional)

  • Type: onAllowanceSignatureRequest?: () => void;
  • Default: undefined

Callback function for when the user is requested to sign the approval transaction.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
	 amount: wei(1, 18)
	 onAllowanceSignatureRequest: () => {} 
  })

onAllowanceSigned (optional)

  • Type: onAllowanceSigned?: (txHash: '0x${string}') => void;
  • Default: undefined

Callback function for when the user is signs the approval transaction.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
	 amount: wei(1, 18)
	 onAllowanceSigned: (txHash) => {} 
  })

onAllowanceSuccess (optional)

  • Type: onAllowanceSuccess?: (receipt: TransactionReceipt) => void;
  • Default: undefined

Callback function for when the approval transaction is successful.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
     amount: wei(1, 18)
     onAllowanceSuccess: (receipt) => {} 
  })

onSignatureRequest (optional)

  • Type: onSignatureRequest?: () => void;
  • Default: undefined

Callback function for when the user is requested to sign the transaction.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
	 amount: wei(1, 18)
	 onSignatureRequest: () => {} 
  })

onSigned (optional)

  • Type: onSigned?: (txHash: '0x${string}') => void;
  • Default: undefined

Callback function for when the user is signs the transaction.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
	 amount: wei(1, 18)
	 onSigned: (txHash) => {} 
  })

onSuccess (optional)

  • Type: onSuccess?: (receipt: TransactionReceipt) => void;
  • Default: undefined

Callback function for when the transaction is successful.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
     amount: wei(1, 18)
     onSuccess: (receipt) => {} 
  })

onError (optional)

  • Type: onError?: (error: unknown) => void;
  • Default: undefined

Callback function for when the transaction fails. This also includes when the user rejects the transaction.

await mintclub
  .network('ethereum')
  .token('MINT')
  .buy({
	  amount: wei(1, 18)
	  onError: (error) => {} 
  })