Carbon SDK
  • Carbon SDK
  • Integration Guide
    • Installation
    • Vocabulary
    • Carbon Instance
    • Marketplace Config
    • Collection Config
    • Listing Items
    • Delisting Items
    • Buying Items
    • Custodial Items
    • Example Asset Flows
  • Team
  • FAQs
Powered by GitBook
On this page
  • Backend
  • Frontend
  1. Integration Guide

Carbon Instance

Create an instance of Carbon to interface with the Solana program. The instance properties program, pdas, instructions, transactions and methods can then be used to interact with the Carbon program.

Backend

The given provider should use a wallet derived from the marketplace authority keypair if being used in a trusted backend environment (e.g. node server). This will allow the instance to use permissioned methods conveniently.

import {AnchorProvider, Wallet} from "@coral-xyz/anchor";
import {Connection, Keypair} from "@solana/web3.js";
import {Carbon} from "@raresloth/carbon-sdk";

const marketplaceAuthorityKey = Keypair.fromSecretKey(Buffer.from(
  JSON.parse(fs.readFileSync(MARKETPLACE_AUTH_KEYPATH, 'utf8'))
));

const connection = new Connection(RPC_URL, { commitment: 'confirmed' })
const provider = new AnchorProvider(
  connection,
  new Wallet(marketplaceAuthorityKey),
  {
    preflightCommitment: 'confirmed',
  }
)
const carbon = new Carbon(provider, marketplaceAuthorityKey.publicKey)

Frontend

When using on the frontend (e.g. react app) this should use the connected wallet instead.

import {AnchorProvider} from "@coral-xyz/anchor";
import {Connection} from "@solana/web3.js";
import {useAnchorWallet} from "@solana/wallet-adapter-react";
import {Carbon} from "@raresloth/carbon-sdk";

const anchorWallet = useAnchorWallet()

const connection = new Connection(RPC_URL, { commitment: 'confirmed' })
const provider = new AnchorProvider(
  connection,
  anchorWallet,
  {
    preflightCommitment: 'confirmed',
  }
)
const carbon = new Carbon(provider, anchorWallet.publicKey)
PreviousVocabularyNextMarketplace Config

Last updated 2 years ago