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

@okxweb3/marketplace-runes

v1.0.0

Published

OKX MarketPlace Runes SDK

Downloads

52

Readme

@okxweb3/marketplace-runes

@okxweb3/marketplace-runes is an SDK designed for Runes trading. It provides a comprehensive set of tools and interfaces to facilitate interaction with the OKX Runes marketplace.

Installation

Install the SDK using npm:

npm i @okxweb3/marketplace-runes

Usage

Initialization

import OkxRunesSDK from @okxweb3/marketplace-runes and new it. Pass in the required parameters as well.

To generate the necessary parameters, please refer to the OKX Developer Management Platform. Here's a usage example:

import { OkxRunesSDK, ADDRESS_TYPE } from '@okxweb3/marketplace-runes'

const sdk = new OkxRunesSDK({
    privateKey: '',  // Your wallet private key for signing transactions
    apikey: '',      // API Key obtained from your application
    secretKey: '',   // Secret Key obtained from your application
    passphrase: '',  // Passphrase created during key application
    addressType: ADDRESS_TYPE.SEGWIT_TAPROOT,  // Wallet address type for buying runes
    projectId: '',   // Project ID created during project application
    requestBaseUrl: '' // okx other website eg: https://www.ouyicn.com/, default is http://www.okx.com/
})

Parameter Details:

| Field Name | Type | Required | Description | | -------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | apikey | String | Yes | API Key from your application. See how to generate it here. | | secretKey | String | Yes | Secret Key from your application. See how to generate it here. | | passphrase | String | Yes | Passphrase created during key application. See how to generate it here. | | projectId | String | Yes | Project ID created during project application. See how to generate it here. | | privateKey | String | Yes | Your wallet private key used for signing transactions. | | addressType | String | Yes | Wallet address type for buying runes.You can import ADDRESS_TYPE from @okxweb3/marketplace-runes and use it. | | requestBaseUrl | String | NO | The domain name used to request the api.okx other website eg: https://www.ouyicn.com/, default is http://www.okx.com/ |

Buying Runes

The SDK supports automatic assembly of purchase transactions, allowing you to obtain the transaction hash (txHash) and network fee. Here's how you can use it:

const buyRunes = async () => {
  const { txHash, networkFee } = await sdk.buy({
     orderIds: [orderId1, orderId2],  // OKX Runes order IDs, you can get orderId by sdk.api.getOrders()
     paymentUtxos: [{                 // UTXOs for transaction assembly
       "txid": "ca79143aea5e22f6cfe8d57c5af6be39fecc7afd5ee931a2060f3fef8754ee15",
       "vout": 3,
       "value": 175136,
     }],
     networkFeeRate: 5,  // Desired network fee rate
   });
}
await buyRunes();

Parameter Details:

| Field Name | Type | Required | Description | | -------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | orderIds | Array | Yes | Unique identifiers for the Runes tokens | | paymentUtxos | Array | Yes | UTXOs used to assemble the purchase transaction. Ensure they contain no other assets and that the total amount covers the order and network fees.You can get your address utxo from here | | networkFeeRate | Number | Yes | The desired network fee rate. |

API

The SDK provides several APIs to query transaction-related information. For detailed parameter usage, please refer to the Runes API.

getOrders

Retrieve orders from the OKX marketplace using this API. The detailed response interface can be found in Runes API. Here's demo:

import { ORDERS_SORT_RULES } from '@okxweb3/marketplace-runes'

const requestApi = async () => {
  const data = await sdk.api.getOrders({
    runesId: '840000:3',  // Desired Runes ID
    sortBy: ORDERS_SORT_RULES.UNIT_PRICE_ASC  // Sorting rule
  });

  // data structure demo, you can get orderId

  // {
  //     "cursor": "1",
  //     "items": [
  //         {
  //           "amount": "889806",
  //           "orderId": 201268,
  //           "ticker": "DOG•GO•TO•THE•MOON",
  //           "tickerId": "840000:3",
  //           "totalPrice": {
  //               "price": "0.05472306",
  //               "satPrice": "5472306",
  //           },
  //           "unitPrice": {
  //               "price": "0.0000000615",
  //               "satPrice": "6.15",
  //           },
  //         }
  //     ]
  //   }

}
await requestApi();

Parameter Details:

| Field Name | Type | Required | Description | | ---------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | runesId | String | Yes | Unique identifier for the Runes token | | cursor | String | No | Cursor for retrieving order sequence numbers (max 1000) | | limit | Number | No | Page size, default 10, max 100. Specifies the maximum number of orders returned. | | sortBy | String | No | Sorting rule, default is ascending by unit price.Options include: unitPriceAsc, unitPriceDesc, totalPriceAsc, totalPriceDesc, listedTimeAsc, listedTimeDesc.  You can importORDERS_SORT_RULES from @okxweb3/marketplace-runes and use it. |

getSellersPsbt

Use this API to obtain seller PSBTs for OKX marketplace orders. Note that the PSBTs do not include the seller's signature. The detailed response interface can be found in Runes API. Here's demo:

const requestApi = async () => {
  // you can get orderId by sdk.api.getOrders()
  const data = await sdk.api.getSellersPsbt([orderId1, orderId2]);

  // data structure demo, you can get seller PSBT from sellerPSBT

  // {
  //   "orderInfos":[
  //     {
  //       "orderId": 11111,
  //       "sellerPSBT": "cHNidP8BAPW+W04EtAAAAAA=",
  //       "orderSource": 34,   //34 - OKX  82-Xverse
  //       "makerFeeAddress": "feeAddress", //platform makerFee address
  //       "makerFee": "0.003", // 0.003 BTC
  //       "takerFeeAddress": "feeAddress", //platform takerFee address
  //       "takerFee": "0.003", // 0.003 BTC
  //     }
  //   ],
  // }

}
await requestApi();

Parameter Details:

| Field Name | Type | Required | Description | | ---------- | ----- | -------- | ----------- | | orderIds | Array | Yes | Order IDs |

sendTransactions

Broadcast Runes purchase transactions with this API to obtain the transaction hash (txHash). The detailed response interface can be found in Runes API. Here's demo:

const requestApi = async () => {
  const data = await sdk.api.sendTransations({ 
    buyerPSBT: psbt, 
    fromAddress: address, 
    orderIds 
  });
  // data structure demo, you can get buy transation txHash

  // {
  //   "txHash": "1",
  // }
}
await requestApi();

Parameter Details:

| Field Name | Type | Required | Description | | ----------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------- | | fromAddress | String | Yes | Buyer's payment address | | orderIds | Array | Yes | IDs of the orders to purchase | | buyerPSBT | String | Yes | Signed buyer PSBT, must be in base64 format, and assembled according to the specified transaction structure |

Middleware

Middleware allows you to access wallet addresses derived from the private key and public key for transaction assembly. It also provides pre-purchase parameters and post-purchase results, enabling actions throughout the purchase lifecycle.

import { OkxRunesSDK } from '@okxweb3/marketplace-runes'

const sdk = new OkxRunesSDK()

// Register middleware
sdk.use(async (ctx, next) => {
  console.log(`Calling ${ctx.type} with params: `, ctx)
  await next()
  console.log(`Result of ${ctx.type}: `, ctx)
})