Sell Creator Coins On Behalf Of Others
In this tutorial, you will learn step-by-step on how to sell any Creator Coins and transfer it to a third-party Base address 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:
Pre-requisites
- Install dependencies
- npm
- yarn
- pnpm
- bun
npm install viem
yarn add viem
pnpm add viem
bun install graphql viem
-
Download the Subject ERC20 Token and Moxie Bonding Curve ABI.
-
Make sure to have some Moxie Creator Coins to sell from 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 Creator Coin Allowance
To check the Creator Coin Allowance, simply call the allowance
function from the specified Creator Coin contract.
When calling the allowance
function set the parameters as follows:
Parameter | Value |
---|---|
owner | Either the senders's EOA wallet or vesting contract address. |
spender | The Moxie bonding curve contract address |
Step 3: Calculate Sell Price For Creator Coins
To calculate the sell price, call the Moxie bonding curve smart contract calculateTokensForSell
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 Creator Coins
If the Creator Coin allowance
is either 0 or less than what is needed to sell the inputted amount of Creator Coins (from Step 2), then approval on the Creator Coin 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 Creator Coin 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 approveSubjectToken
function that you can call by providing the Creator Coin's subject to the _subject
parameter to approve a specific Creator Coin in your vesting contract to be accessible by other Moxie protocol contracts.
After the approval, all the Creator Coin in the vesting contract will be available for selling.
Step 5: Execute Contract Call
Lastly, call the sellSharesForV2
function on the Moxie bonding curve contract to execute the Creator Coin selling transaction:
- Viem (TS)
import client from "./client";
import { MoxieBondingCurveABI } from "./abi/ProtocolContracts#MoxieBondingCurve.json";
try {
clientwriteContract({
account,
address: MoxieBondingCurveAddress, // or user's vesting contract address
abi: MoxieBondingCurveABI,
functionName: "sellSharesForV2",
args: [
// subject address
"0x338fDD513Ed2eC7ee1249Ee286F967FC56492C78",
// amount of FT to sell
BigInt("10000000000000000"),
// the 3rd party address that will receive the Moxie Token from the selling
"0xadd746be46ff36f10c81d6e3ba282537f4c68077",
// (minimum) amount of Moxie to receive from the selling, calculated from step 2
BigInt("263749847732490543"),
// referrer address
"0x2211d1d0020daea8039e46cf1367962070d77da9",
],
});
} catch (e) {
console.error(e);
}
Congrats! 🥳🎉 You've just successfully sold a Creator Coin and transfer it to a third-party address!
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.