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

@nfttrader-io/sdk-js

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nfttrader-io/sdk-js

The NFT Trader official javascript SDK.

  • 1.0.23
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

NFT Trader Javascript SDK

Welcome to the official repository of the P2P OTC NFT Trader platform developed by the official NFT Trader team!

The primary goal with this package is to offer web3 developers a simple design to integrate our robust NFT Trader technology inside other external DApps (Decentralized Applications). This is open for all developers who would like to unlock the ability for your applications and protocols to have a system which allows for the secure swapping of NFTs (erc721), ERC20, ERC1155 tokens on Ethereum and other digital assets on EVM congruent chains.

The package is available for Node.js and browser platforms.

Installation

Using npm:

npm install @nfttrader-io/sdk-js

Using local js file (copy the file under dist folder):

<script src="/path/to/your/js/nfttrader-sdk.js"></script>

Using unpkg.com

<script src="https://unpkg.com/@nfttrader-io/sdk-js@latest/dist/nfttrader-sdk.js"></script>

CommonJS usage

const NFTTraderSDK = require('@nfttrader-io/sdk-js')
const sdk = new NFTTraderSDK(...)

Browser usage

const sdk = new NFTTraderSDK(...)

Introduction

The NFTTraderSDK class object is the action to which you can interact with the NFT Trader Smart Contract in a convenient manner. It contains a set of methods that allow you to simplify the interaction process with the blockchain. The SDK is compatible on the following blockchains:

  • Ethereum Mainnet
  • Ethereum Rinkeby
  • Polygon
  • Polygon Mumbai
  • xDai chain (Gnosis chain)

What Can I Do With This SDK?

With the NFT Trader Javascript SDK you can create a swap order, finalize a swap order, edit the Taker of the order or cancel a swap order. Furthermore, it provides you some other utility based methods that allow you to read details of the order book, listen to specific events from the smart contract and includes helper functions in order to help you format the parameters of the NFT Trader Smart Contract in the correct way. We will describe everything in more detail throughout the next sections, so do not worry if you don't fully understand what has already been stated. 🤓

The end purpose is very simple once you learn how to master the SDK. You will be able to include these sets of functionalities directly into your own platform and enable the swapping features for NFTs, ERC20 tokens and other digital assets. This is a very useful tool for many applications, particularly if you are planning to build a game with a swap market feature for trading game assets or an application / market in which you want to integrate a method for your users to swap assets with other users. There are many web3 protocols which will find this SDK useful for the purpose of trading digital assets.

Table Of Contents

How The Swap Works

The following scheme describes visually how the swap logic works.

how-swap-works-nfttrader

Here is a more in depth explanation for the image above. The swap "cycle" is composed by the following phases:

  • Create swap phase (mandatory)
  • Close swap phase (optional)
  • Edit Taker phase (optional)
  • Cancel swap phase (optional)
Create Swap Phase

The creation of the swap is marked as "mandatory" because it is the first operation you need to do in order to start the interaction with the system. When you are in this phase you can define the assets that will be included with the trades (ex. the Creator assets and the Taker assets), the Taker (Counterparty) of the swap, the duration and other parameters will be described in the next sections. Once a user has created the swap, the NFT Trader Smart Contract will emit a swapEvent with some useful data you can track for fulfilling your needs. Furthermore, the SDK will emit other events placed at the javascript level in order to give you the ability to avoid listening directly the events on the blockchain. These types of events will be described in the next sections.

Close Swap Phase

This phase is marked as "optional" since is not mandatory for the Taker (counterparty) of the swap to close it. The Taker could be a specific address or everyone (it depends how the swap is configured in the Creation Swap phase). If the swap is to be closed by the Taker, the NFT Trader Smart Contract will emit a swapEvent with some useful data that you can track to fulfill your needs. As for the Creation Swap Phase, the SDK will emit events placed at the javascript level in order to track the transaction status.

Edit Taker Phase

This phase is marked as "optional" since is not mandatory for the Creator to edit the Taker address. It could be useful for the Creator to edit the Taker if he wants to change the counterparty because he has found a new person interested with their deal. This phase can be performed only by the Creator of the swap and no one else. Once a user has changed the Taker, the NFT Trader Smart Contract will emit a counterpartEvent with the data related to the new counterparty that will be involved in the swap. As for the Creation Swap Phase, the SDK will emit events placed at the javascript level in order to track the transaction status.

Cancel Swap Phase

This phase is marked as "optional" since it is not mandatory for the Creator to cancel the swap. Only the Creator can cancel a swap and no one else. Once a user has changed the Taker, the NFT Trader Smart Contract will emit a counterpartEvent with the data related to the new counterparty involved in the swap. As for the Creation Swap Phase, the SDK will emit events placed at the javascript level in order to track the transaction status.

Initialize The NFTTraderSDK Object

In order to interact with the NFT Trader Smart Contract you will need to create a new instance of the NFTTraderSDK object. There two basic ways to initialize this object because basically there are two possible scenarios.

  • You are developing a Backend Platform (Node.js).
  • You are developing a Single Page Application, a Website or a Plugin.

If you are developing a backend platform you can initialize the NFTTraderSDK object in this way.

const ethers = require("ethers")
const sdk = new NFTTraderSDK({
  ethers : ethers, //you need to provide the instance of ethers js library
  jsonRpcProvider : 'RPC_URL_PROVIDER', //example: infura
  network : 'NETWORK', //example: 'ETHEREUM', 'RINKEBY', 'POLYGON', 'MUMBAI',
  signer : {
    privateKey : '<PRIVATE_KEY_OF_A_WALLET_OR_ACCOUNT>'
  },
  avoidPrivateKeySigner : false // this is optional parameter. If the value specified is true, the NFTTraderSDK will be able to read the data from the smart contract, not to send transactions. In this way you can avoid to specify the signer property during the initialization.
})

//start to perform operation with the sdk
sdk.method1(...)
sdk.method2(...)

Why do I need to specify a private key? Because in a backend environment you do not have a crypto wallet like Metamask or similar that can provide you a way to interact directly with the blockchain, by sending a transaction to a smart contract. This is why you will need to specify a private key. In order to be able to perform writing operations on the blockchain. Provide the privateKey parameter is not mandatory. If you specify the avoidPrivateKeySigner parameter to false, you will be able to use the NFTTraderSDK object but only for performing read operations on the smart contract.

IMPORTANT. WE NEVER STORE YOUR PRIVATE KEY. privateKey IS A READ-ONLY PARAMETER.

If you are developing a Frontend Application (SPA), a Website or a Plugin you can initialize the NFTTraderSDK object in this manner.

window.addEventListener('load', async () => {
  const sdk = new NFTTraderSDK({
    ethers : ethers, //you need to provide the instance of ethers js library
    web3Provider : window.ethereum, //or an instance of ethers.providers.Web3Provider
    network : 'NETWORK', //example: 'ETHEREUM', 'RINKEBY', 'POLYGON', 'MUMBAI', 'XDAI'
  })

  provider = new ethers.providers.Web3Provider(window.ethereum)
  await provider.send('eth_requestAccounts', [])

  //start to perform operation with the sdk
  sdk.method1(...)
  sdk.method2(...)
})

Once you have initialized the NFTTraderSDK object you will be ready to perform write or read operations on the NFT Trader Smart Contract.

Instance methods

The SDK will provide you the following list of methods:

- createSwap(config[, gasLimit[, gasPrice]]) : Promise(void)
- closeSwap(config[, gasLimit[, gasPrice]]) : Promise(void)
- cancelSwap(swapId[, gasLimit[, gasPrice]]) : Promise(void)
- editTaker(swapId, addressTaker[, gasLimit[, gasPrice]]) : Promise(void)
- on(eventName, callbackFn) : void
- off(eventName[, callbackFn]) : void
- getSwapDetails(swapId) : Promise(Object)
- getSwapAssets(swapId) : Promise(Object)
- isERC20WhiteListed(erc20Address) : Promise(boolean)
- isNFTBlacklisted(assetAddress) : Promise(boolean)
- getPayment() : Promise(Object)
- getReferenceAddress() : Promise(Object)
- isBannedAddress(address) : Promise(boolean)
- getEthersJSInstance() : Ethers
- setBlocksNumberConfirmationRequired(blocksNumberConfirmationRequired) : void
- getNetworksAvailable() : Object
- estimateGasCreateSwap() : ethers.BigNumber | null
- estimateGasCloseSwap() : ethers.BigNumber | null
- estimateGasCancelSwap() : ethers.BigNumber | null
- estimateGasEditTaker() : ethers.BigNumber | null
- getRoyaltyRegistriesEngines() : Object

Keywords

FAQs

Package last updated on 16 Jul 2022

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