1Sat Ordinals - JS Library
js-1sat-ord
A Javascript library for creating and managing 1Sat Ordinal inscriptions and transactions. Uses @bsv/sdk
under the hood.
It provides functions for listing, cancelling and purchasing Ordinal Lock transactions.
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:
Usage
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 traqnsaction.
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
: Custom signer object for transaction signingadditionalPayments
: Additional payments to include in the transaction
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