1Sat Ordinals - JS Library
js-1sat-ord
Use 1Sat SDK for maintained 1Sat development. This library is being retired; the documentation below is retained for existing integrations and historical reference.
The replacement is a set of packages, not a drop-in API replacement:
Wallet actions and transaction workflows
Script templates
Indexer/API access
Shared types
See the 1Sat SDK setup and package guide before migrating. New contract support belongs in that SDK.
The retirement release retains the existing cancellation and purchase APIs while deprecating listing creation. OrdLock is being deprecated in favor of a more advanced locking contract.
Legacy documentation
A Javascript library for creating and managing 1Sat Ordinal inscriptions and transactions. Uses @bsv/sdk under the hood.
The historical API includes Ordinal Lock transaction functions. Listing creation is deprecated; cancellation and purchase remain available in the retirement release.
It also privides helpers for fetching utxos for payments, nfts, and tokens.
Install
Install the library, and it's peer dependency. We recommend using Bun for the best performance, but you can also use Yarn or npm:
# Using Bun (recommended)
bun add js-1sat-ord @bsv/sdk
# Using Yarn
yarn add js-1sat-ord @bsv/sdk
# Using npm
npm i js-1sat-ord @bsv/sdkUsage
Example
Prepare some utxos to use in the following format. Be sure to use base64 encoded scripts. We use this encoding because it makes large scripts smaller in size.
You can use the helper fetchPayUtxos(address) to fetch unspent transaction outputs from the public 1Sat API and create the scripts with the correct encoding (base64). This should be a BSV address, not your ordinals address. Note: By default the script encoding will be base64, but you can provide a 2nd parameter and specify hex or asm encoding for the script property.
Note: Utxo and NftUtxo and TokenUtxo have an optional pk field for specifying a Private Key for unlocking this utxo. This is helpful when multiple keys own the inputs and you need to spend them in a single transaction.
For NFTUtxos:
For Token Utxos:
Prepare Inscription
For a markdown inscription, you can create a string and convert it to base64:
Prepare Keys
Be sure to use different keys for ordinals and normal payments:
Create Ordinals
The createOrdinals function creates a transaction with inscription outputs:
Send Ordinals
Sends ordinals to the given destinations:
Deploy a BSV21 Token
Transfer BSV21 Tokens
Note: To burn tokens you can set the optional burn parameter to true Note: You can use the optional splitConfig parameter to configure how and when to split token change outputs, and whether change outputs should include metadata. Note: You can use the optional tokenInputMode parameter to configure whether all tokens are consumed, or only what's needed. Default is needed.
Send Utxos
Sends utxos to the given destination:
Create Ordinal Listings
Creates a listing using an "Ordinal Lock" script. Can be purchased by anyone by sending a specific amount to the provided address.
Purchase Ordinal Listing
Cancel Ordinal Listings
Spends the ordinal lock without payment, returning the ordinal to the address specified in the listing contract.
Additional Configuration Options
Each function accepts additional configuration options not shown in the examples above. These may include:
changeAddress: Address to send change to (if not provided, defaults to the payment key's address)satsPerKb: Satoshis per kilobyte for fee calculationmetaData: MAP (Magic Attribute Protocol) metadata to include in inscriptionssigner: LocalSigner or RemoteSigner object for adding Sigma protocol signatures to transactions (provides replay protection)additionalPayments: Additional payments to include in the transaction
Using Sigma Protocol Signatures
Several functions support optional Sigma protocol signatures for replay protection:
Supported functions: createOrdinals, sendOrdinals, transferOrdToken, deployBsv21Token, sendUtxos, createOrdListings, createOrdTokenListings
Refer to the function documentation for a complete list of configuration options for each function.
Broadcasting
Using with Bundlers
Since this package depends on @bsv/sdk there should be no issue with bundlers.
Resources
There is a public 1Sat API which is documented here:
https://ordinals.gorillapool.io/api/docs
Last updated