0

I am trying to figure out how you set a price value in USD on Solana. My project needs to be fixed to USDC pricing, not Sol. I get it has something to do with an SPL token but the guard value is only in sol. There is no clear documentation for this. Any help would be welcomed.

2
  • Is this using the candy machine?
    – Jimii
    Commented Jul 5 at 6:24
  • 1
    Jimii, Yes I have created with Candy Machine V3. The information you have provided looks promising, but I am still very new to the process and will need to study it deeper to see how to apply it. I have created everything with Sugar CLI using the config.json file through a tutorial I found on YouTube Created by Keystrokes. So I am still piecing together information. Commented Jul 6 at 15:55

1 Answer 1

0

Here's how you can do so using the core candy guard program, but the process will be similar if you are using the TM candy guard program.

You can do so using the token-payment candy guard.

import {
    create as createCM,
    mintV1 as MintV1CoreAsset,
    mplCandyMachine,
} from "@metaplex-foundation/mpl-core-candy-machine";

import {
    findAssociatedTokenPda,
    setComputeUnitLimit,
} from "@metaplex-foundation/mpl-toolbox";
import {
    generateSigner,
    keypairIdentity,
    Signer,
    some,
    transactionBuilder,
    publicKey as UMIPublicKey,
    Transaction as UMITransaction,
} from "@metaplex-foundation/umi";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";

import { createCollectionV1, mplCore } from "@metaplex-foundation/mpl-core";

import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
import { clusterApiUrl, Connection, Keypair } from "@solana/web3.js";
import { uintSecret } from "./helpers";

const connection = new Connection(clusterApiUrl("devnet"));

const umi = createUmi(connection);

const keypair = umi.eddsa.createKeypairFromSecretKey(uintSecret);

umi.use(keypairIdentity(keypair)).use(mplCore()).use(mplCandyMachine());

const OORTECH_URI_PREFIX =
    "https://devnet.standard.us-east-1.oortech.com/asset/metadata/";

async function createCollectionAsset(
    collectionMint: Signer,
    name: string,
    uri: string
): Promise<UMITransaction> {
    let createCollectionTxBuilder = await createCollectionV1(umi, {
        collection: collectionMint,
        name,
        uri,
    });

    return createCollectionTxBuilder.buildWithLatestBlockhash(umi);
}

async function createCoreCM(
    candyMachine: Signer,
    collectionMint: string,
    itemsAvailable: number,
    prefixName: string,
    prefixUri: string = OORTECH_URI_PREFIX
): Promise<UMITransaction> {
    const USDCMint = UMIPublicKey(
        "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
    );

    const createCMTxBuilder = await createCM(umi, {
        candyMachine,
        collection: UMIPublicKey(collectionMint),
        collectionUpdateAuthority: umi.identity,
        itemsAvailable,
        authority: umi.identity.publicKey,
        configLineSettings: some({
            // prefixName: "Example Asset #",
            prefixName,
            nameLength: prefixName.length,
            prefixUri,
            uriLength: prefixUri.length,
            isSequential: false,
        }),
        guards: {
            tokenPayment: some({
                amount: 300,
                mint: USDCMint,
                destinationAta: findAssociatedTokenPda(umi, {
                    mint: USDCMint,
                    owner: umi.identity.publicKey,
                })[0],
            }),
        },
    });

    return createCMTxBuilder.buildWithLatestBlockhash(umi);
}

async function mintFromCoreCM(candyMachine: string, collection: string) {
    const asset = generateSigner(umi);

    const USDCMint = UMIPublicKey(
        "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
    );

    let mintTxBuilder = await transactionBuilder()
        .add(setComputeUnitLimit(umi, { units: 80_000 }))
        .add(
            MintV1CoreAsset(umi, {
                candyMachine: UMIPublicKey(candyMachine),
                asset,
                collection: UMIPublicKey(collection),
                mintArgs: {
                    tokenPayment: some({
                        mint: USDCMint,
                        destinationAta: findAssociatedTokenPda(umi, {
                            mint: USDCMint,
                            owner: umi.identity.publicKey,
                        })[0],
                    }),
                },
            })
        )
        .buildWithLatestBlockhash(umi);

    let tx = toWeb3JsTransaction(mintTxBuilder);
    tx.sign([Keypair.fromSecretKey(asset.secretKey), me]);

    const txId = await connection.sendTransaction(tx);
    console.log(`https://explorer.solana.com/tx/${txId}?cluster=devnet`);
}

ref, token program: https://developers.metaplex.com/candy-machine/guards/token-payment

ref, token-22: https://developers.metaplex.com/candy-machine/guards/token2022-payment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.