Tokens Module
The tokens module provides encrypted PushDrop token creation, listing with decryption, on-chain transfer, redemption, and MessageBox-based P2P transfer.
Source: src/modules/tokens.ts
createToken()
async createToken(options: TokenOptions): Promise<TokenResult>Create an encrypted PushDrop token.
options.data
any
required
Token data (object or string, will be JSON-serialized)
options.to
string
self
Recipient public key
options.basket
string
'tokens'
Basket to store the token
options.protocolID
[number, string]
[0, 'token']
PushDrop protocol ID
options.keyID
string
'1'
PushDrop key ID
options.satoshis
number
1
Satoshis locked in the token
Returns: TokenResult
What happens:
Serializes
datato JSON stringEncrypts using
client.encrypt()with the specified protocol/keyCreates a PushDrop locking script with the ciphertext
Creates the transaction via
createAction()Stores
{ protocolID, keyID, counterparty }incustomInstructionsfor later decryption
listTokenDetails()
List tokens in a basket with automatic decryption.
basket
string
'tokens'
Basket to query
Returns: Array of TokenDetail
Behavior:
Fetches outputs with locking scripts and custom instructions
Decodes PushDrop fields from each output
Reads
protocolID,keyID,counterpartyfromcustomInstructionsDecrypts the PushDrop field using
client.decrypt()Falls back to
counterparty: 'anyone'if'self'decryption failsSkips non-PushDrop outputs silently
sendToken()
Transfer a token to another key via on-chain transaction.
options.basket
string
Basket containing the token
options.outpoint
string
Token outpoint ("txid.vout")
options.to
string
Recipient's public key
Returns: TransactionResult
What happens (two-step signing):
Lists outputs with
include: 'entire transactions'to get BEEF dataFinds the target token by outpoint
Decodes the PushDrop fields from the source script
Creates a new PushDrop locking script for the recipient with a new
keyIDCalls
createAction()with the token as input — returns asignableTransactionSigns the input using
PushDrop.unlock()templateCalls
signAction()with the unlocking script to finalize
redeemToken()
Spend/destroy a token (reclaims the locked satoshis).
options.basket
string
Basket containing the token
options.outpoint
string
Token outpoint ("txid.vout")
Returns: TransactionResult
Behavior: Same two-step signing flow as sendToken(), but with no new output — the token is consumed.
sendTokenViaMessageBox()
Transfer a token to another key via MessageBox P2P messaging.
options.basket
string
Basket containing the token
options.outpoint
string
Token outpoint
options.to
string
Recipient's public key
Returns: TransactionResult
Behavior:
Same two-step signing as
sendToken()After signing, sends the transaction via
PeerPayClient.sendMessage()to thesimple_token_inboxmessage boxMessage body contains:
{ transaction, protocolID, keyID, sender, outputIndex }
listIncomingTokens()
List tokens waiting in the MessageBox inbox.
Returns: Array of incoming token messages:
acceptIncomingToken()
Accept an incoming token from the MessageBox inbox.
token
any
required
Token object from listIncomingTokens()
basket
string
'tokens'
Basket to store the accepted token
Returns: { accepted: true, basket: string, sender: string }
Behavior:
Internalizes the transaction using
basket insertionprotocolStores
{ protocolID, keyID, counterparty }incustomInstructionsAcknowledges the message to remove it from the inbox
Last updated
