npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

element-aggregator-sdk

v0.0.5

Published

Javascript SDK for the www.element.market

Downloads

2

Readme

Element Aggregator Sdk

https://badges.frapsoft.com/os/mit/mit.svg?v=102

Published on GitHub and npm

Synopsis

This is an aggregator trade SDK for element.market, a marketplace for NFTs.

You get started by requesting an API key and instantiating your own sdk. Then you can create orders off-chain or fulfill orders on-chain.

Installation

Install element-aggregator-sdk, in your project, run:

npm install --save element-aggregator-sdk

If your project run in browser environment, you need install crypto-browserify, stream-browserify, buffer, and config webpack.config.js:

#install crypto-browserify, stream-browserify, buffer
npm install --save crypto-browserify
npm install --save stream-browserify
npm install --save buffer
#config webpack.config.js
module.exports = function (webpackEnv) {
  ...
  return {
    ...
    resolve: {
        ...
        fallback: {
            crypto: require.resolve("crypto-browserify"),
            stream: require.resolve("stream-browserify"),
            buffer: require.resolve('buffer/'),
        },
    },
    ...
    plugins: [
        ...
        new webpack.ProvidePlugin({
            Buffer: ['buffer', 'Buffer'],
        }),
    ],
  }
};

Getting Started

Querying Orders

Query orders by the asset contract address.

import { queryOrders } from 'element-aggregator-sdk'

const queryResponse = await queryOrders('apiKey', {
  chainId: chainId,
  assetContractAddress: assetAddress
});
export interface QueryParams {
  // Query by smart contract address for the asset category.
  assetContractAddress: string;
  // Chain id: 1 - Ethereum, 4 - Rinkeby. Default 1.
  chainId?: number;
  // Filter by a list of token IDs for the order's asset, Needs to be defined together with assetContractAddress.
  assetTokenIds?: BigNumberish[];
  // Result page index, default 1.
  pageIndex?: number;
  // Result page size, max 50, default 20.
  pageSize?: number;
}

export async function queryOrders(apiKey: string, query: QueryParams, timeout = 15000): Promise<QueryResponse>;
export interface QueryResponse {
  // Result current page index
  pageIndex: number;
  // Result page size
  pageSize: number;
  // Result total page count
  totalPageCount: number;
  // Result record count
  totalItemCount: number;
  // The order list
  list: OrderResponse[];
}

export interface OrderResponse {
  // The smart contract address for the asset category.
  contractAddress: string;
  // The asset token id.
  tokenId: string;
  // The best listing order id.
  bestAskOrderID: number;
  // Order detail string.
  bestAskOrderString: string;
  // Order standard: `opensea`, `element-ex-v3` or `looksrare`.
  bestBidOrderStandard: string;
  // Order sale kind: 0 - fixed price, 1 - dutch auction, 2 - english auction.
  bestAskSaleKind: number;
  // Order pay token.
  bestAskToken: string;
  // Price in `bestAskToken`, unit: ether(10^18 wei). Note it's just for display.
  bestAskPrice: number;
  // Price in `NativeToken`(e.g. ETH on chain Ethereum), unit: ether(10^18 wei).
  bestAskPriceBase: number;
  // Price in USD, Unit: USD.
  bestAskPriceUSD: number;
  // Listing time. Timestamp(unit: seconds).
  bestAskListingDate: number;
  // Expiration time. Timestamp(unit: seconds).
  bestAskExpirationDate: number;
}

Checking Orders

Check whether the orders are valid.

import { checkOrdersValidity } from 'element-aggregator-sdk'

const ordersValidity = await checkOrdersValidity({
  chainId: chainId,
  orders: queryResponse.list
});

for (let i = 0; i < ordersValidity.length; i++) {
  console.log(`i=${i}, validity=${ordersValidity[i]}`);
}
export interface CheckOrdersParams {
  // Chain id: 1 - Ethereum, 4 - Rinkeby. Default 1.
  chainId?: number;
  rpcUrl?: string;
  orders?: OrderResponse[];
  orderStrings?: string[];
}

export async function checkOrdersValidity(params: CheckOrdersParams): Promise<boolean[]>;

Filling Orders

import { fillOrders } from 'element-aggregator-sdk'

const signer = await getSigner(chainId);
const tx = await fillOrders({
  chainId: chainId,
  signer: signer,
  orders: queryResponse.list
});
console.log("tx.hash: ", tx.hash);

const receipt = await tx.wait(1);
console.log("receipt: ", receipt);
export interface FillOrdersParams {
  signer: Signer;
  chainId?: number;
  orders?: OrderResponse[];
  orderStrings?: string[];
  gasPrice?: BigNumberish;
  maxFeePerGas?: BigNumberish;
  maxPriorityFeePerGas?: BigNumberish;
}

export async function fillOrders(params: FillOrdersParams): Promise<TransactionResponse>;

Learning More

The test case is here.

If you need extra help, support is free! You can email us [email protected].