New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nftgo/gotrading

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nftgo/gotrading

JavaScript SDK for the NFTGo trading aggregator. Let users buy crypto collectibles and other cryptogoods from multi-marketplaces , all on your own site!

  • 1.0.15
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
6
Weekly downloads
 
Created
Source

GoTrading-js

node Discord Twitter

Table of Contents

Introduction

GoTrading is an open-source development kit that enables you to build your own NFT trading aggregator and marketplace. The SDK provides a comprehensive set of tools and APIs that greatly simplify the development process of a general trading aggregator like Gem.xyz or Blur.io, and allows developers to access real-time order feed and NFT transaction data. With the SDK, you can easily aggregate orders and functionality from mainstream marketplaces such as Opensea, Looksrare, Blur, x2y2, Sudoswap, etc, all in your products and communities.

Key Features

  • Simple and easy-to-use API
  • Real-time market data access
  • Code is easy to customize and extend
  • Supports Bulk Listing and Bulk Buying

Supported Marketplaces

GoTrading currently aggregates the following marketplaces, and we will continue to add more marketplaces in the future.

MarketplaceCreate ListingsFulfill ListingsCreate OffersFulfill OffersCancel Listings/OffersProtocol
OpenSeaYesYesYesYesYesseaport-v1.5
BlurYesYesYesYesYesblur
LooksRareYesYesYesYesYeslooksrare-v2
X2Y2YesYesYesYesYesx2y2
SudoswapNoYesNoYesNosudoswap/sudoswap-v2
CryptoPunksNoYesNoYesYescryptopunks
ArtblocksNoYesNoYesYesseaport-v1.5
ReservoirNoYesNoYesYesseaport-v1.5
ENSVisionNoYesNoYesYesseaport-v1.5
MagicallyNoYesNoYesYesseaport-v1.5
AlienswapNoYesNoYesYesseaport-v1.5
OrdinalsNoYesNoYesYesseaport-v1.5
SoundNoYesNoYesYesseaport-v1.5
NFTGOYesYesYesYesYesseaport-v1.5/payment-processor-v2

Supported Chains

GoTrading currently supports the following chains:

  • Ethereum Mainnet
  • Sepolia Testnet ( Comming Soon )
  • Polygon Mainnet ( Comming Soon )

Requirements

  • Node.js >= 16.14
  • web3 >= 1.8.2
  • ethers >= 5.6.9, < 6.1

You can do this by running the following commands:

npm install web3 ethers@5.6.9

Quickstart

1. Install the SDK.

With npm :

npm install @nftgo/gotrading

With yarn :

yarn add @nftgo/gotrading

2. Import and init the GoTrading SDK.

Instantiate the instance of GoTrading using your etheres provider with API key.

import { init, Config } from '@nftgo/gotrading';
import Web3 from 'web3';

// Create a new Web3 Provider to interact with the Ethereum network.
const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io') //Replace with your own provider

// Configure the necessary parameters for the Trade Aggregator API client.
const configs: Config = {
  apiKey: "YOUR-API-KEY", // Replace with your own API Key.
  web3Provider: provider,
  walletConfig: {
    address: "Your wallet address",
    privateKey: "Your private key"
  }, // Replace with your wallet info.
};

// Create a Trade Aggregator client instance and return the utility and aggregator objects of the Trade Aggregator API.
const {aggregator, utils, orderFetcher} = init(configs);

If you need to obtain an API key or a custom plan, please contact our support team. You can reach us by submitting a form, and we will respond to you within 1-2 business days.

Please note that we may need to understand your use case and requirements in order to provide you with the API key and custom plan that best suits your needs. Thank you for your interest in our service, and we look forward to working with you.

3. Fulfill Listings


import { init, Config, FulfillListingsReq } from '@nftgo/gotrading';

async function demo() {
  const config: Config = {};

  const { aggregator, utils } = init(config);

  const {listingDTOs} = await orderFetcher.getOrdersByContract({
    contractAddress: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d', // bayc contract address
    orderType: OrderType.Listing
  })
  const req: FulfillListingsReq = {
    buyer: 'xxx', // your address
    orderIds: listingDTOs.map(listingDTO => listingDTO.orderId),
    safeMode: false,
  };

  // get actions, meanwhile we provide executeActions function to deal with actions
  const { actions, executeActions } = await aggregator.fulfillListings(req);


  // case 1
  // RECOMMEND: use execute functions we provide
  await executeActions({
    onTaskExecuted(task) {
      // do something with completed task info
      console.log(task.action.name, task.status);
    },
  });
  console.log('success');

  // case 2
  // execute actions by yourself
  const executor = utils.createActionExecutor(actions);
  for (const task of executor) {
    await task.execute();
    console.log(task.action.name, task.status);
  }
  console.log('success');
}

SDK Core Methods

To use the GoTrading SDK, you need to initialize the SDK with your API key. After initialization, you can use the following methods to interact with the GoTrading API.

import { init, Config } from '@nftgo/gotrading';

const config: Config = {
  apiKey: 'YOUR-API-KEY',
  openSeaApiKeyConfig: {
    apiKey: 'YOUR-OPENSEA-API-KEY',
    requestsPerInterval: 10, // 10 requests per interval
    interval: 1000, // 1 second
  },
  looksRareApiKeyConfig: {
    apiKey: 'YOUR-LOOKSRARE-API-KEY',
    requestsPerInterval: 10, // 10 requests per interval
    interval: 1000, // 1 second
  },
  x2y2ApiKeyConfig: {
    apiKey: 'YOUR-X2Y2-API-KEY',
    requestsPerInterval: 10, // 10 requests per interval
    interval: 1000, // 1 second
  },
  walletConfig: {
    address: 'Your wallet address',
    privateKey: 'Your private key',
  }, // Replace with your wallet info.
};

const goTrading = init(config);

Marketplace

The Marketplace methods are used to create and fulfill listings and offers across all marketplaces.

Create Listings
import { CreateListingsReq, Orderbook, OrderKind } from '@nftgo/gotrading';

const req: CreateListingsReq = {
  maker: 'xxx', // your address
  params: [
    {
      token: '0x97a20815a061eae224c4fdf3109731f73743db73:2',
      quantity: 1,
      weiPrice: '1000',
      orderKind: OrderKind.SeaportV15,
      orderbook: Orderbook.Opensea,
      listingTime: '1688625367',
      expirationTime: '1689858225',
      currency: '0x0000000000000000000000000000000000000000',
      automatedRoyalties: true,
    },
    {
      token: '0x97a20815a061eae224c4fdf3109731f73743db73:2',
      quantity: 1,
      weiPrice: '1000',
      orderKind: OrderKind.X2Y2,
      orderbook: Orderbook.X2Y2,
      listingTime: '1688625367',
      expirationTime: '1689858225',
      currency: '0x0000000000000000000000000000000000000000',
    },
    {
      token: '0x97a20815a061eae224c4fdf3109731f73743db73:2',
      quantity: 1,
      weiPrice: '1000',
      orderKind: OrderKind.LooksRareV2,
      orderbook: Orderbook.LooksRare,
      listingTime: '1688625367',
      expirationTime: '1689858225',
      currency: '0x0000000000000000000000000000000000000000',
    },
    {
      token: '0x61628d84d0871a38f102d5f16f4e69ee91d6cdd9:7248',
      quantity: 1,
      weiPrice: '1000',
      orderKind: OrderKind.SeaportV15,
      orderbook: Orderbook.Opensea,
      listingTime: '1688625367',
      expirationTime: '1689858225',
      currency: '0x0000000000000000000000000000000000000000',
      automatedRoyalties: true,
    },
  ],
};

const response = await goTrading.aggregator.createListings(req);

await response.executeActions({
  onTaskExecuted(task) {
    console.log(task.action.name, task.status);
  },
});


Create Offers
import { CreateOffersReq, Orderbook, OrderKind } from '@nftgo/gotrading';

const req: CreateOffersReq = {
  maker: 'xxx', // your address
  params: [
    {
      collection: '0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63',
      weiPrice: '10000000000',
      orderKind: OrderKind.SeaportV15,
      orderbook: Orderbook.Opensea,
      listingTime: '1689017272',
      expirationTime: '1688017272',
      quantity: 2,
    },
    {
      collection: '0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63',
      weiPrice: '10000000000',
      orderKind: OrderKind.LooksRareV2,
      orderbook: Orderbook.Looksrare,
      listingTime: '1689017272',
      expirationTime: '1688017272',
      quantity: 1,
    }
  ],
};

const response = await goTrading.aggregator.createOffers(req);

await response.executeActions({
  onTaskExecuted(task) {
    console.log(task.action.name, task.status);
  },
});

Fulfill Listings
import { FulfillListingsReq, Orderbook, OrderKind } from '@nftgo/gotrading';

const orderIds = ['xxx', 'yyy']; // pass the listing ids you want to fulfill

const req: FulfillListingsReq = {
  buyer: 'xxx', // your address
  orderIds,
};

const response = await goTrading.aggregator.fulfillListings(req);

await response.executeActions({
  onTaskExecuted(task) {
    console.log(task.action.name, task.status);
  },
});

Fulfill Offers
import { FulfillOffersReq, Orderbook, OrderKind } from '@nftgo/gotrading';

const orderIds = ['xxx', 'yyy']; // pass the offer ids you want to fulfill

const req: FulfillOffersReq = {
  sellerAddress: 'xxx', // your address
  offerFulfillmentIntentions: [
    {
      orderId: orderIds[0],
      contractAddress: "0x02d66f9d220553d831b239f00b5841280ddcfaf3",
      tokenId: "1",
      quantity: 1,
    },
    {
      orderId: orderIds[1],
      contractAddress: "0x02d66f9d220553d831b239f00b5841280ddcfaf3",
      tokenId: "2",
      quantity: 1,
    },
  ],
};

const response = await goTrading.aggregator.fulfillOffers(req);

await response.executeActions({
  onTaskExecuted(task) {
    console.log(task.action.name, task.status);
  },
});

Cancel Orders
import { CancelOrdersReq, Orderbook, OrderKind } from '@nftgo/gotrading';


const cancelOrdersReq: CancelOrdersReq = {
  callerAddress: 'xxx', // your address
  orders: [
    {
      orderId: 'aaa',
      orderType: OrderType.Listing,
    },
    {
      orderId: 'bbb',
      orderType: OrderType.Offer,
    },
  ],
};

const response = await goTrading.aggregator.cancelOrders(cancelOrdersReq);

await response.executeActions({
  onTaskExecuted(task) {
    console.log(task.action.name, task.status);
  },
});

OrderFetcher

Get Orders By Contract
import { OrderType, GetOrdersByContractReq } from '@nftgo/gotrading';

// Get listings by contractAddress
const getOrdersByContractReq: GetOrdersByContractReq = {
  contractAddress: '0x97a20815a061eae224c4fdf3109731f73743db73',
  orderType: OrderType.Listing,
};

const { listingDTOs } = await goTrading.orderFetcher.getOrdersByContract(getOrdersByContractReq);

// Get offers by contractAddress
const getOffersByContractReq: GetOrdersByContractReq = {
  contractAddress: '0x97a20815a061eae224c4fdf3109731f73743db73',
  orderType: OrderType.Offer,
};

const { offerDTOs } = await goTrading.orderFetcher.getOrdersByContract(getOrdersByContractReq);


Get Orders By NFT
import { OrderType, GetOrdersByNftsReq } from '@nftgo/gotrading';

// Get listings by nft
const getOrdersByNftsReq: GetOrdersByNftsReq = {
  contractAddress: '0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63',
  tokenId: '1',
  orderType: OrderType.Listing,
};

const { listingDTOs } = await goTrading.orderFetcher.getOrdersByNFT(getOrdersByNftsReq);

// Get offers by nft
const getOffersByNftsReq: GetOrdersByNftsReq = {
  contractAddress: '0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63',
  tokenId: '1',
  orderType: OrderType.Offer,
};

const { offerDTOs } = await goTrading.orderFetcher.getOrdersByNFT(getOffersByNftsReq);

Get Orders By Ids
import { OrderType, GetOrdersByIdsReq } from '@nftgo/gotrading';

const getOrdersByIdsReq: GetOrdersByIdsReq = {
  orders: [
    {
      orderId: 'xxx',
      orderType: OrderType.Listing,
    },
    {
      orderId: 'yyy',
      orderType: OrderType.Offer,
    },
  ],
};

const { listingDTOs, offerDTOs } = await goTrading.orderFetcher.getOrdersByIds(getOrdersByIdsReq);

Get Orders By Maker
import { OrderType, GetOrdersByMakerReq } from '@nftgo/gotrading';

// Get listings by maker
const getOrdersByMakerReq: GetOrdersByMakerReq = {
  maker: 'xxx', // your address
  orderType: OrderType.Listing,
};

const { listingDTOs } = await goTrading.orderFetcher.getOrdersByMaker(getOrdersByMakerReq);

// Get offers by maker
const getOffersByMakerReq: GetOrdersByMakerReq = {
  maker: 'xxx', // your address
  orderType: OrderType.Offer,
};

const { offerDTOs } = await goTrading.orderFetcher.getOrdersByMaker(getOffersByMakerReq);

Utils

Questions & Feedback

If you have any questions, issues, or feedback, please file an issue on GitHub, or drop us a message on our Discord channel for the SDK.

License

This project is licensed under the BSD-3-Clause license.

FAQs

Package last updated on 26 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc