Buy Creator Coins
In this tutorial, you will learn step-by-step on how to buy any Creator Coins on the Moxie protocol through the bonding curve contract.
While the tutorial shown here will be using viem in TypeScript, you should be able to use other programming language and their web3-equivalent libraries to execute the Creator Coin buying process. Alternatives web3 libraries you can use are:
Starting 22nd November 2024, any EOA wallet or contracts on Base can buy Creator Coins without needing to hold any Moxie Pass.
Pre-requisites
- Install dependencies
- npm
- yarn
- pnpm
- bun
npm install viem
yarn add viem
pnpm add viem
bun install graphql viem
-
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
First, setup a viem client and provide the mnemonic of your account to create an account
instance:
Ensure to store the mnemonic securley and privately as an environment variable so that your wallet address will not be compromised.
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
To check the Moxie Token Allowance, simply call the allowance
function from Moxie token contract.
When calling the allowance
function set the parameters as follows:
Parameter | Value |
---|---|
owner | Either the user's EOA wallet or vesting contract address. |
spender | The Moxie bonding curve contract address |
Step 3: Calculate Buy Price For Creator Coins
To calculate the buy price, call the Moxie bonding curve smart contract calculateTokensForBuy
with the following parameters:
Parameter | Value |
---|---|
_subjectTokenAmount | how much FT user wanna buy (in wei) |
_subject | The subject address associated to the Creator Coins. |
Step 4: Approve Moxie Tokens
If the Moxie token allowance
is either 0 or less than what is needed to buy the inputted amount of Creator Coins (from Step 2), then approval on the Moxie Token will need to be initiated to ensure that the buy transaction is successful.
Otherwise, if there is sufficient allowance
value, skip to Step 5 to execute the buy Creator Coins transaction.
EOA Wallet
From EOA wallet, simply call the approve
function on the Moxie token with the following variables:
Parameter | Description |
---|---|
spender | the Moxie bonding curve address |
value | the amount of Moxie to buy FT |
Vesting Contract
From vesting contract there is the approveProtocol
function that you can call to approve all Moxie token in your vesting contract to be accessible by other Moxie protocol contracts.
After the approval, all the Moxie Token in the vesting contract will be available for Creator Coin purchase.
Step 5: Execute Contract Call
Lastly, call the buySharesV2
function on the Moxie bonding curve contract to execute the Creator Coin purchase transaction:
- Viem (TS)
import client from "./client";
import { MoxieBondingCurveABI } from "./abi/ProtocolContracts#MoxieBondingCurve.json";
try {
client.writeContract({
account,
address: "0x373065e66B32a1C428aa14698dFa99BA7199B55E",
abi: MoxieBondingCurveABI,
functionName: "buySharesV2",
args: [
// subject address
"0x338fDD513Ed2eC7ee1249Ee286F967FC56492C78",
// amount of Moxie in wei to purchase the FT, calculated from Step 2
BigInt("263749847732490543"),
// (minimum) amount of FT to buy in wei
BigInt("10000000000000000"),
// referrer address
"0xadd746be46ff36f10c81d6e3ba282537f4c68077",
],
});
} catch (e) {
console.error(e);
}
Congrats! 🥳🎉 You've just successfully purchased a Creator Coin!
Developer Support
If you have any questions or need help with other use cases, feel free to join the Moxie Official Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.