Buy Fan Tokens
Pre-requisites
-
Install dependencies
-
Download the Moxie Token and Moxie Bonding Curve ABI.
-
Make sure to have Moxie token in your wallet and sufficient Base ETH to cover the transaction fees.
Step 1: Setup Client
config.ts
import { createWalletClient, createPublicClient, http } from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { base } from "viem/chains";
const account = mnemonicToAccount("YOUR_WALLET_MNEMONIC");
const client = createWalletClient({
account,
chain: base,
transport: http(),
});
export const publicClient = createPublicClient({
chain: base,
transport: http(),
});
Step 2: Check Moxie Token Allowance
Step 3: Calculate Buy Price For Fan Tokens
Step 4: Approve Moxie Tokens
Step 5: Execute Contract Call
import client from "./client";
import { MoxieBondingCurveABI } from "./abi/ProtocolContracts#MoxieBondingCurve.json";
try {
client.writeContract({
account,
address: "0x373065e66B32a1C428aa14698dFa99BA7199B55E",
abi: MoxieBondingCurveABI,
functionName: "buyShares",
args: [
// subject address
"0x338fDD513Ed2eC7ee1249Ee286F967FC56492C78",
// amount of Moxie to purchase the FT, calculated from step 2
BigInt("263749847732490543"),
// (minimum) amount of FT to buy
BigInt("10000000000000000"),
],
});
} catch (e) {
console.error(e);
}
Developer Support
If you have any questions or need help with other use cases, feel free to join the /airstack Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.