Skip to content

SolDapper/mcswap-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcswap-sdk

Javascript SDK for the McSwap Protocol

McSwap is a Trustless Smart Escrow Protocol on the Solana Blockchain that enables app developers to build their own Marketplaces and OTC services for digital assets. Direct onchain revenue sharing is built-in and allows developers to define usage fees for when they or their application's users create or execute McSwap Escrows through their apps and tools.

powered by solana

Install

npm i mcswap-sdk

Import

import mcswap from 'mcswap-sdk';

Methods

mcswap-spl

mcswap.splCreate
mcswap.splExecute
mcswap.splCancel
mcswap.splReceived
mcswap.splSent

mcswap-core

mcswap.coreCreate
mcswap.coreCancel
mcswap.coreExecute
mcswap.coreReceived
mcswap.coreSent

mcswap-nft

mcswap.nftCreate
mcswap.nftCancel
mcswap.nftExecute
mcswap.nftReceived
mcswap.nftSent

mcswap-pnft

mcswap.pnftCreate
mcswap.pnftCancel
mcswap.pnftExecute
mcswap.pnftReceived
mcswap.pnftSent

mcswap-cnft

mcswap.cnftCreate
mcswap.cnftCancel
mcswap.cnftExecute
mcswap.cnftReceived
mcswap.cnftSent

utilities

mcswap.tx
mcswap.send
mcswap.status
mcswap.fetch
mcswap.fee

Examples

example setup

import { Keypair } from "@solana/web3.js";
const rpc = "https://staked.helius-rpc.com?api-key=YOUR-KEY";
const secret = [1,2,3,4,5,~];
const signer = Keypair.fromSecretKey(new Uint8Array(secret));

base fees

gets the current base fee for the protocol by asset standard

const fee = await mcswap.fee({
    rpc: rpc, 
    display: true,
    standard: "nft" // nft, pnft, cnft, core
});
console.log(fee);

mcswap-spl

splCreate Escrow

const tx = await mcswap.splCreate({
    rpc: rpc,
    builder: true, // builder false will return ix for tx only
    blink: false, // blink true will return a base64 formatted object
    tolerance: 1.2, // cu estimate multiplier for padding if needed
    priority: "Medium", // priority fee level
    convert: true, // convert true because we're passing decimal values for amounts below
    affiliateWallet: "ACgZcmgmAnMDxXxZUo9Zwg2PS6WQLXy63JnnLmJFYxZZ",
    affiliateFee: "0.0009",
    seller: "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere", // provider
    token1Mint: "So11111111111111111111111111111111111111112",
    token1Amount: "0.001",
    token2Mint: false,
    token2Amount: false,
    buyer: false, // buyer false makes this a public listing
    token3Mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    token3Amount: "0.003",
    token4Mint: false,
    token4Amount: false
});
if(tx.tx){
    tx.tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx.tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    if(status!="finalized"){console.log(status);}
    else{
        console.log(status);
        const escrow = await mcswap.fetch({
            rpc:rpc, display:true, standard:"spl", escrow:tx.escrow
        });
        console.log(escrow);
    }
}
else{
    console.log(tx);
}

splCancel Escrow

const tx = await mcswap.splCancel({
    rpc: rpc,
    escrow: "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL" // escrow id (acct)
});
if(typeof tx.status!="undefined"){console.log(tx);}
else{
    tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    console.log(status);
}

splExecute Escrow

const tx = await mcswap.splExecute({
    rpc: rpc,
    convert: true,
    affiliateWallet: "ACgZcmgmAnMDxXxZUo9Zwg2PS6WQLXy63JnnLmJFYxZZ",
    affiliateFee: "0.0009",
    escrow: "3pjxfm25WWwD9BcWSqBFamJKYgEpNAnEz8mEmxk9biBQ",
    buyer: "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"
});
if(typeof tx.status!="undefined"){console.log(tx);}
else{
    tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    console.log(status);
}

splReceived Escrows

const splReceived = await mcswap.splReceived({
    rpc: rpc,
    display: true,
    wallet: "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"
});
console.log(splReceived);

splSent Escrows

const splSent = await mcswap.splSent({
    rpc: rpc,
    display: true,
    private: false, // (default) private false returns public listings
    wallet: "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"
});
console.log(splSent);

mcswap-nft

nftCreate, pnftCreate, cnftCreate, coreCreate

const tx = await mcswap.nftCreate({
    rpc: rpc,
    builder: true,
    blink: false,
    convert: true,
    tolerance: 1.2,
    priority: "Medium",
    affiliateWallet: "ACgZcmgmAnMDxXxZUo9Zwg2PS6WQLXy63JnnLmJFYxZZ",
    affiliateFee: "0.0009",
    seller: "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere",
    sellerMint: "5Jk6hn3rR1DJjtDU4MzgDuN3SXH4nfHiYgqmEVhGyEUt",
    buyer: false, // buyer false makes this a public listing
    buyerMint: false,
    lamports: "0.0001",
    tokenMint: "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",
    units: "0.01"
});
if(tx.status){console.log(tx);}
else{
    tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    if(status!="finalized"){console.log("status", status);}
    else{
        console.log(status);
        const escrow = await mcswap.fetch({
            rpc: rpc,
            display: true,
            standard: "nft", // nft, pnft, cnft, core
            sellerMint: "5Jk6hn3rR1DJjtDU4MzgDuN3SXH4nfHiYgqmEVhGyEUt",
            buyerMint: false
        });
        console.log(escrow);
    }
}

nftCancel, pnftCancel, cnftCancel, coreCancel

const tx = await mcswap.nftCancel({
    rpc: rpc,
    blink: false,
    sellerMint: "5Jk6hn3rR1DJjtDU4MzgDuN3SXH4nfHiYgqmEVhGyEUt",
    buyerMint: false,
});
if(tx.status){console.log(tx);}
else{
    tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    console.log(status);
}

nftExecute, pnftExecute, cnftExecute, coreExecute

const tx = await mcswap.nftExecute({
    rpc: rpc,
    blink: false,
    convert: true,
    tolerance: 1.2,
    priority: "Medium",
    affiliateWallet: "ACgZcmgmAnMDxXxZUo9Zwg2PS6WQLXy63JnnLmJFYxZZ",
    affiliateFee: "0.0009",
    buyer: "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL",
    sellerMint: "5Jk6hn3rR1DJjtDU4MzgDuN3SXH4nfHiYgqmEVhGyEUt",
    buyerMint: false,
});
if(tx.status){console.log(tx);}
else{
    tx.sign([signer]);
    const signature = await mcswap.send(rpc,tx);
    console.log("signature", signature);
    console.log("awaiting status...");
    const status = await mcswap.status(rpc,signature);
    console.log(status);
}

nftReceived, pnftReceived, cnftReceived, coreReceived

const nftReceived = await mcswap.nftReceived({
    rpc: rpc,
    display: true,
    wallet: "2jcih7dUFmEQfMUXQQnL2Fkq9zMqj4jwpHqvRVe3gGLL"
});
console.log(nftReceived);

nftSent, pnftSent, cnftSent, coreSent

const nftSent = await mcswap.nftSent({
    rpc: rpc,
    display: true,
    private: false, // private false returns public listings by default
    wallet: "7Z3LJB2rxV4LiRBwgwTcufAWxnFTVJpcoCMiCo8Z5Ere"
});
console.log(nftSent);

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks