Options
All
  • Public
  • Public/Protected
  • All
Menu

@stacks/transactions npm

Construct, decode transactions and work with Clarity smart contracts on the Stacks blockchain.

Installation

npm install @stacks/transactions

Overview

This library supports the creation of the following Stacks transaction types:

  1. STX token transfer
  2. Smart contract deploy
  3. Smart contract function call

Key Generation

import { createStacksPrivateKey, makeRandomPrivKey, getPublicKey } from '@stacks/transactions';

// Random key
const privateKey = makeRandomPrivKey();
// Get public key from private
const publicKey = getPublicKey(privateKey);

// Private key from hex string
const key = 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01';
const privateKey = createStacksPrivateKey(key);

STX Token Transfer Transaction

import {
  makeSTXTokenTransfer,
  makeStandardSTXPostCondition,
  broadcastTransaction,
} from '@stacks/transactions';
import { StacksTestnet, StacksMainnet } from '@stacks/network';
const BigNum = require('bn.js');

// for mainnet, use `StacksMainnet()`
const network = new StacksTestnet();

const txOptions = {
  recipient: 'SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159',
  amount: new BigNum(12345),
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01',
  network,
  memo: 'test memo',
  nonce: new BigNum(0), // set a nonce manually if you don't want builder to fetch from a Stacks node
  fee: new BigNum(200), // set a tx fee if you don't want the builder to estimate
  anchorMode: AnchorMode.Any
};

const transaction = await makeSTXTokenTransfer(txOptions);

// to see the raw serialized tx
const serializedTx = transaction.serialize().toString('hex');

// broadcasting transaction to the specified network
broadcastTransaction(transaction, network);

Smart Contract Deploy Transaction

import { makeContractDeploy, broadcastTransaction, AnchorMode } from '@stacks/transactions';
import { StacksTestnet, StacksMainnet } from '@stacks/network';
const BigNum = require('bn.js');

// for mainnet, use `StacksMainnet()`
const network = new StacksTestnet();

const txOptions = {
  contractName: 'contract_name',
  codeBody: fs.readFileSync('/path/to/contract.clar').toString(),
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01',
  network,
};

const transaction = await makeContractDeploy(txOptions);

broadcastTransaction(transaction, network);

Smart Contract Function Call

import { makeContractCall, BufferCV, broadcastTransaction, AnchorMode } from '@stacks/transactions';
import { StacksTestnet, StacksMainnet } from '@stacks/network';
const BigNum = require('bn.js');

// for mainnet, use `StacksMainnet()`
const network = new StacksTestnet();

// Add an optional post condition
// See below for details on constructing post conditions
const postConditionAddress = 'SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE';
const postConditionCode = FungibleConditionCode.GreaterEqual;
const postConditionAmount = new BigNum(1000000);
const postConditions = [
  makeStandardSTXPostCondition(postConditionAddress, postConditionCode, postConditionAmount),
];

const txOptions = {
  contractAddress: 'SPBMRFRPPGCDE3F384WCJPK8PQJGZ8K9QKK7F59X',
  contractName: 'contract_name',
  functionName: 'contract_function',
  functionArgs: [bufferCVFromString('foo')],
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01',
  validateWithAbi: true,
  network,
  postConditions,
  anchorMode: AnchorMode.Any,
};

const transaction = await makeContractCall(txOptions);

broadcastTransaction(transaction, network);

In this example we construct a contract-call transaction with a post condition. We have set the validateWithAbi option to true, so the makeContractCall builder will attempt to fetch this contracts ABI from the specified Stacks network, and validate that the provided functionArgs match what is described in the ABI. This should help you avoid constructing invalid contract-call transactions. If you would prefer to provide your own ABI instead of fetching it from the network, the validateWithABI option also accepts ClarityABI objects, which can be constructed from ABI files like so:

import { readFileSync } from 'fs';

const abi: ClarityAbi = JSON.parse(readFileSync('abi.json').toString());

Sponsoring Transactions

To generate a sponsored transaction, first create and sign the transaction as the origin. The sponsored property in the options object must be set to true.

import { makeContractCall, BufferCV, AnchorMode } from '@stacks/transactions';
const BigNum = require('bn.js');

const txOptions = {
  contractAddress: 'SPBMRFRPPGCDE3F384WCJPK8PQJGZ8K9QKK7F59X',
  contractName: 'contract_name',
  functionName: 'contract_function',
  functionArgs: [bufferCVFromString('foo')],
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01',
  validateWithAbi: true,
  sponsored: true,
  anchorMode: AnchorMode.Any,
};

const transaction = await makeContractCall(txOptions);
const serializedTx = transaction.serialize().toString('hex');

The serialized transaction can now be passed to the sponsoring party which will sign the sponsor portion of the transaction and set the fee.

import {
  sponsorTransaction,
  BufferReader,
  deserializeTransaction,
  broadcastTransaction,
} from '@stacks/transactions';
import { StacksTestnet, StacksMainnet } from '@stacks/network';
const BigNum = require('bn.js');

const bufferReader = new BufferReader(Buffer.from(serializedTx));
const deserializedTx = deserializeTransaction(bufferReader);
const sponsorKey = '770287b9471081c8acd37d57190c7a70f0da2633311cc120853537362d32e67c01';
const fee = new BigNum(1000);

const sponsorOptions = {
  transaction: deserializedTx,
  sponsorPrivateKey: sponsorKey,
  fee,
};

const sponsoredTx = await sponsorTransaction(sponsorOptions);

// for mainnet, use `StacksMainnet()`
const network = new StacksTestnet();
broadcastTransaction(sponsoredTx, network);

Supporting multi-signature transactions

To generate a multi-sig transaction, first create an unsigned transaction. The numSignatures and publicKeys properties in the options object must be set:

import {
  makeUnsignedSTXTokenTransfer,
  createStacksPrivateKey,
  pubKeyfromPrivKey,
  publicKeyToString,
  TransactionSigner,
  standardPrincipalCV,
  BufferReader,
  AnchorMode,
} from '@stacks/transactions';
const BigNum = require('bn.js');

const recipient = standardPrincipalCV('SP3FGQ8...');
const amount = new BigNum(2500000);
const fee = new BigNum(0);
const nonce = new BigNum(0);
const memo = 'test memo';

// private keys of the participants in the transaction
const privKeyStrings = ['6d430bb9...', '2a584d89...', 'd5200dee...'];

// create private key objects from string array
const privKeys = privKeyStrings.map(createStacksPrivateKey);

// corresponding public keys
const pubKeys = privKeyStrings.map(pubKeyfromPrivKey);

// create public key string array from objects
const pubKeyStrings = pubKeys.map(publicKeyToString);

const transaction = await makeUnsignedSTXTokenTransfer({
  recipient,
  amount,
  fee,
  nonce,
  memo,
  numSignatures: 2, // number of signature required
  publicKeys: pubKeyStrings, // public key string array with >= numSignatures elements
  anchorMode: AnchorMode.Any,
});

const serializedTx = transaction.serialize();

This transaction payload can be passed along to other participants to sign. In addition to meeting the numSignatures requirement, the public keys of the parties who did not sign the transaction must be appended to the signature.

// deserialize and sign transaction
const bufferReader = new BufferReader(serializedTx);
const deserializedTx = deserializeTransaction(bufferReader);

const signer = new TransactionSigner(deserializedTx);

// first signature
signer.signOrigin(privKeys[0]);

// second signature
signer.signOrigin(privKeys[1]);

// after meeting the numSignatures requirement, the public
// keys of the participants who did not sign must be appended
signer.appendOrigin(pubKeys[2]);

// the serialized multi-sig tx
const serializedSignedTx = deserializedTx.serialize();

Calling Read-only Contract Functions

Read-only contract functions can be called without generating or broadcasting a transaction. Instead it works via a direct API call to a Stacks node.

const contractAddress = 'ST3KC0MTNW34S1ZXD36JYKFD3JJMWA01M55DSJ4JE';
const contractName = 'kv-store';
const functionName = 'get-value';
const buffer = bufferCVFromString('foo');
const network = new StacksTestnet();
const senderAddress = 'ST2F4BK4GZH6YFBNHYDDGN4T1RKBA7DA1BJZPJEJJ';

const options = {
  contractAddress,
  contractName,
  functionName,
  functionArgs: [buffer],
  network,
  senderAddress,
};

const result = await callReadOnlyFunction(options);

Constructing Clarity Values

Building transactions that call functions in deployed clarity contracts requires you to construct valid Clarity Values to pass to the function as arguments. The Clarity type system contains the following types:

  • (tuple (key-name-0 key-type-0) (key-name-1 key-type-1) ...)
    • a typed tuple with named fields.
  • (list max-len entry-type)
    • a list of maximum length max-len, with entries of type entry-type
  • (response ok-type err-type)
    • object used by public functions to commit their changes or abort. May be returned or used by other functions as well, however, only public functions have the commit/abort behavior.
  • (optional some-type)
    • an option type for objects that can either be (some value) or none
  • (buff max-len)
    • byte buffer or maximum length max-len.
  • principal
    • object representing a principal (whether a contract principal or standard principal).
  • bool
    • boolean value ('true or 'false)
  • int
    • signed 128-bit integer
  • uint
    • unsigned 128-bit integer

This library contains Typescript types and classes that map to the Clarity types, in order to make it easy to construct well-typed Clarity values in Javascript. These types all extend the abstract class ClarityValue.

// construct boolean clarity values
const t = trueCV();
const f = falseCV();

// construct optional clarity values
const nothing = noneCV();
const something = someCV(t);

// construct a buffer clarity value from an existing Buffer
const buffer = Buffer.from('foo');
const bufCV = bufferCV(buffer);

// construct signed and unsigned integer clarity values
const i = intCV(-10);
const u = uintCV(10);

// construct principal clarity values
const address = 'SP2JXKMSH007NPYAQHKJPQMAQYAD90NQGTVJVQ02B';
const contractName = 'contract-name';
const spCV = standardPrincipalCV(address);
const cpCV = contractPrincipalCV(address, contractName);

// construct response clarity values
const errCV = responseErrorCV(trueCV());
const okCV = responseOkCV(falseCV());

// construct tuple clarity values
const tupCV = tupleCV({
  a: intCV(1),
  b: trueCV(),
  c: falseCV(),
});

// construct list clarity values
const l = listCV([trueCV(), falseCV()]);

If you develop in Typescript, the type checker can help prevent you from creating wrongly-typed Clarity values. For example, the following code won't compile since in Clarity lists are homogeneous, meaning they can only contain values of a single type. It is important to include the type variable BooleanCV in this example, otherwise the typescript type checker won't know which type the list is of and won't enforce homogeneity.

const l = listCV<BooleanCV>([trueCV(), intCV(1)]);

Post Conditions

Three types of post conditions can be added to transactions:

  1. STX post condition
  2. Fungible token post condition
  3. Non-Fungible token post condition

For details see: https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md#transaction-post-conditions

STX post condition

// With a standard principal
const postConditionAddress = 'SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE';
const postConditionCode = FungibleConditionCode.GreaterEqual;
const postConditionAmount = new BigNum(12345);

const standardSTXPostCondition = makeStandardSTXPostCondition(
  postConditionAddress,
  postConditionCode,
  postConditionAmount
);

// With a contract principal
const contractAddress = 'SPBMRFRPPGCDE3F384WCJPK8PQJGZ8K9QKK7F59X';
const contractName = 'test-contract';

const contractSTXPostCondition = makeContractSTXPostCondition(
  contractAddress,
  contractName,
  postConditionCode,
  postConditionAmount
);

Fungible token post condition

// With a standard principal
const postConditionAddress = 'SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE';
const postConditionCode = FungibleConditionCode.GreaterEqual;
const postConditionAmount = new BigNum(12345);
const assetAddress = 'SP62M8MEFH32WGSB7XSF9WJZD7TQB48VQB5ANWSJ';
const assetContractName = 'test-asset-contract';
const fungibleAssetInfo = createAssetInfo(assetAddress, assetContractName);

const standardFungiblePostCondition = makeStandardFungiblePostCondition(
  postConditionAddress,
  postConditionCode,
  postConditionAmount,
  fungibleAssetInfo
);

// With a contract principal
const contractAddress = 'SPBMRFRPPGCDE3F384WCJPK8PQJGZ8K9QKK7F59X';
const contractName = 'test-contract';
const assetAddress = 'SP62M8MEFH32WGSB7XSF9WJZD7TQB48VQB5ANWSJ';
const assetContractName = 'test-asset-contract';
const fungibleAssetInfo = createAssetInfo(assetAddress, assetContractName);

const contractFungiblePostCondition = makeContractFungiblePostCondition(
  contractAddress,
  contractName,
  postConditionCode,
  postConditionAmount,
  fungibleAssetInfo
);

Non-fungible token post condition

// With a standard principal
const postConditionAddress = 'SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE';
const postConditionCode = NonFungibleConditionCode.Owns;
const assetAddress = 'SP62M8MEFH32WGSB7XSF9WJZD7TQB48VQB5ANWSJ';
const assetContractName = 'test-asset-contract';
const assetName = 'test-asset';
const tokenAssetName = 'test-token-asset';
const nonFungibleAssetInfo = createAssetInfo(assetAddress, assetContractName, assetName);

const standardNonFungiblePostCondition = makeStandardNonFungiblePostCondition(
  postConditionAddress,
  postConditionCode,
  nonFungibleAssetInfo,
  tokenAssetName
);

// With a contract principal
const contractAddress = 'SPBMRFRPPGCDE3F384WCJPK8PQJGZ8K9QKK7F59X';
const contractName = 'test-contract';

const contractNonFungiblePostCondition = makeContractNonFungiblePostCondition(
  contractAddress,
  contractName,
  postConditionCode,
  nonFungibleAssetInfo,
  tokenAssetName
);

Helper functions

Conversion of Clarity Values to JSON

Clarity Values represent values of Clarity contracts. If a JSON format is required the helper function cvToJSON can be used.

cvToJSON(hexToCV(tx.tx_result.hex))

Index

References

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

References

randomBytes

Re-exports randomBytes

Type aliases

BooleanCV

BooleanCV: TrueCV | FalseCV

ClarityAbiType

ClarityAbiTypeBool

ClarityAbiTypeBool: "bool"

ClarityAbiTypeBuffer

ClarityAbiTypeBuffer: { buffer: { length: number } }

Type declaration

  • buffer: { length: number }
    • length: number

ClarityAbiTypeInt128

ClarityAbiTypeInt128: "int128"

ClarityAbiTypeList

ClarityAbiTypeList: { list: { length: number; type: ClarityAbiType } }

Type declaration

ClarityAbiTypeNone

ClarityAbiTypeNone: "none"

ClarityAbiTypeOptional

ClarityAbiTypeOptional: { optional: ClarityAbiType }

Type declaration

ClarityAbiTypePrimitive

ClarityAbiTypePrincipal

ClarityAbiTypePrincipal: "principal"

ClarityAbiTypeResponse

ClarityAbiTypeResponse: { response: { error: ClarityAbiType; ok: ClarityAbiType } }

Type declaration

ClarityAbiTypeStringAscii

ClarityAbiTypeStringAscii: { string-ascii: { length: number } }

Type declaration

  • string-ascii: { length: number }
    • length: number

ClarityAbiTypeStringUtf8

ClarityAbiTypeStringUtf8: { string-utf8: { length: number } }

Type declaration

  • string-utf8: { length: number }
    • length: number

ClarityAbiTypeTraitReference

ClarityAbiTypeTraitReference: "trait_reference"

ClarityAbiTypeTuple

ClarityAbiTypeTuple: { tuple: { name: string; type: ClarityAbiType }[] }

Type declaration

ClarityAbiTypeUInt128

ClarityAbiTypeUInt128: "uint128"

ClarityAbiTypeUnion

ClarityValue

MultiSigHashMode

MultiSigHashMode: SerializeP2SH | SerializeP2WSH

OptionalCV

OptionalCV<T>: NoneCV | SomeCV<T>

Type parameters

PostCondition

PostCondition: STXPostCondition | FungiblePostCondition | NonFungiblePostCondition

PostConditionPrincipal

PostConditionPrincipal: StandardPrincipal | ContractPrincipal

PrincipalCV

ReadOnlyFunctionResponse

ResponseCV

SingleSigHashMode

SingleSigHashMode: SerializeP2PKH | SerializeP2WPKH

SpendingCondition

StacksMessage

TransactionAuthFieldContents

TransactionAuthFieldContents: StacksPublicKey | MessageSignature

TxBroadcastResult

TxBroadcastResultOk

TxBroadcastResultOk: string

TxBroadcastResultRejected

TxBroadcastResultRejected: { error: string; reason: TxRejectedReason; reason_data: any; txid: string }

Type declaration

Variables

Const CLARITY_INT_SIZE

CLARITY_INT_SIZE: 128 = 128

Const COINBASE_BUFFER_LENGTH_BYTES

COINBASE_BUFFER_LENGTH_BYTES: 32 = 32

Const COMPRESSED_PUBKEY_LENGTH_BYTES

COMPRESSED_PUBKEY_LENGTH_BYTES: 32 = 32

Const DEFAULT_CHAIN_ID

DEFAULT_CHAIN_ID: Mainnet = ...

Const DEFAULT_CORE_NODE_API_URL

DEFAULT_CORE_NODE_API_URL: "https://stacks-node-api.mainnet.stacks.co" = 'https://stacks-node-api.mainnet.stacks.co'

Const DEFAULT_TRANSACTION_VERSION

DEFAULT_TRANSACTION_VERSION: Mainnet = ...

Const MAX_STRING_LENGTH_BYTES

MAX_STRING_LENGTH_BYTES: 128 = 128

Const MEMO_MAX_LENGTH_BYTES

MEMO_MAX_LENGTH_BYTES: 34 = 34

Const RECOVERABLE_ECDSA_SIG_LENGTH_BYTES

RECOVERABLE_ECDSA_SIG_LENGTH_BYTES: 65 = 65

Const UNCOMPRESSED_PUBKEY_LENGTH_BYTES

UNCOMPRESSED_PUBKEY_LENGTH_BYTES: 64 = 64

Functions

abiFunctionToString

addressFromHashMode

addressFromPublicKeys

addressFromVersionHash

addressHashModeToVersion

addressToString

  • addressToString(address: Address): string

broadcastRawTransaction

  • broadcastRawTransaction(rawTx: Buffer, url: string, attachment?: Buffer): Promise<TxBroadcastResult>
  • Broadcast the signed transaction to a core node

    Parameters

    • rawTx: Buffer

      the raw serialized transaction buffer to broadcast

    • url: string

      the broadcast endpoint URL

    • Optional attachment: Buffer

    Returns Promise<TxBroadcastResult>

    that resolves to a response if the operation succeeds

broadcastTransaction

Const bufferCV

Const bufferCVFromString

  • bufferCVFromString(str: string): BufferCV

callReadOnlyFunction

cloneDeep

  • cloneDeep<T>(obj: T): T

codeBodyString

compressPublicKey

contractPrincipalCV

contractPrincipalCVFromAddress

contractPrincipalCVFromStandard

createAddress

  • createAddress(c32AddressString: string): Address

createAssetInfo

  • createAssetInfo(addressString: string, contractName: string, assetName: string): AssetInfo

createContractPrincipal

  • createContractPrincipal(addressString: string, contractName: string): ContractPrincipal

createEmptyAddress

createFungiblePostCondition

createLPList

createLPString

createMemoString

createMessageSignature

createMultiSigSpendingCondition

createNonFungiblePostCondition

createSTXPostCondition

createSingleSigSpendingCondition

createStacksPrivateKey

createStacksPublicKey

createStandardPrincipal

createTransactionAuthField

cvToHex

cvToJSON

cvToString

  • cvToString(val: ClarityValue, encoding?: "tryAscii" | "hex"): string

cvToValue

deserializeAddress

deserializeAssetInfo

deserializeCV

  • deserializeCV<T>(serializedClarityValue: BufferReader | Buffer | string): T

deserializeLPList

deserializeLPString

deserializeMemoString

deserializeMessageSignature

deserializeMultiSigSpendingCondition

deserializePostCondition

deserializePrincipal

deserializePublicKey

deserializeSingleSigSpendingCondition

deserializeSpendingCondition

deserializeStacksMessage

deserializeTransaction

deserializeTransactionAuthField

emptyMessageSignature

encodeClarityValue

estimateContractDeploy

  • Estimate the total transaction fee in microstacks for a contract deploy

    Parameters

    • transaction: StacksTransaction

      the token transfer transaction to estimate fees for

    • Optional network: StacksNetwork

      the Stacks network to estimate transaction for

    Returns Promise<BigNum>

    a promise that resolves to number of microstacks per byte

estimateContractFunctionCall

  • Estimate the total transaction fee in microstacks for a contract function call

    Parameters

    • transaction: StacksTransaction

      the token transfer transaction to estimate fees for

    • Optional network: StacksNetwork

      the Stacks network to estimate transaction for

    Returns Promise<BigNum>

    a promise that resolves to number of microstacks per byte

estimateTransfer

  • Estimate the total transaction fee in microstacks for a token transfer

    Parameters

    • transaction: StacksTransaction

      the token transfer transaction to estimate fees for

    • Optional network: StacksNetwork

      the Stacks network to estimate transaction for

    Returns Promise<BigNum>

    a promise that resolves to number of microstacks per byte

Const exceedsMaxLengthBytes

  • exceedsMaxLengthBytes(string: string, maxLengthBytes: number): boolean

Const falseCV

getAbi

  • Fetch a contract's ABI

    Parameters

    • address: string

      the contracts address

    • contractName: string

      the contracts name

    • network: StacksNetwork

      the Stacks network to broadcast transaction to

    Returns Promise<ClarityAbi>

    that resolves to a ClarityAbi if the operation succeeds

getAddressFromPrivateKey

  • getAddressFromPrivateKey(privateKey: string | Buffer, transactionVersion?: TransactionVersion): string

getAddressFromPublicKey

  • getAddressFromPublicKey(publicKey: string | Buffer, transactionVersion?: TransactionVersion): string

getCVTypeString

getNonce

  • getNonce(address: string, network?: StacksNetwork): Promise<BigNum>
  • Lookup the nonce for an address from a core node

    Parameters

    • address: string

      the c32check address to look up

    • Optional network: StacksNetwork

      the Stacks network to look up address on

    Returns Promise<BigNum>

    a promise that resolves to an integer

getPublicKey

getSignatureRecoveryParam

  • getSignatureRecoveryParam(signature: string): number

getTypeString

getTypeUnion

Const hash160

  • hash160(input: Buffer): Buffer

Const hashP2PKH

  • hashP2PKH(input: Buffer): string

Const hashP2SH

  • hashP2SH(numSigs: number, pubKeys: Buffer[]): string

Const hexStringToInt

  • hexStringToInt(hexString: string): number

hexToCV

Const intCV

  • intCV(value: string | number | Buffer): IntCV

Const intToHexString

  • intToHexString(integer: number, lengthBytes?: number): string

Const isClarityAbiBuffer

Const isClarityAbiList

Const isClarityAbiOptional

Const isClarityAbiPrimitive

Const isClarityAbiResponse

Const isClarityAbiStringAscii

Const isClarityAbiStringUtf8

Const isClarityAbiTuple

isClarityName

  • isClarityName(name: string): boolean

isCompressed

isSingleSig

Const leftPadHex

  • leftPadHex(hexString: string): string

Const leftPadHexToLength

  • leftPadHexToLength(hexString: string, length: number): string

listCV

  • listCV<T>(values: T[]): ListCV<T>

makeContractCall

makeContractDeploy

makeContractFungiblePostCondition

  • makeContractFungiblePostCondition(address: string, contractName: string, conditionCode: FungibleConditionCode, amount: BigNum, assetInfo: string | AssetInfo): FungiblePostCondition
  • Generates a fungible token post condition with a contract principal

    Returns a fungible token post condition object

    Parameters

    • address: string

      the c32check address

    • contractName: string

      the name of the contract

    • conditionCode: FungibleConditionCode

      the condition code

    • amount: BigNum

      the amount of fungible tokens

    • assetInfo: string | AssetInfo

      asset info describing the fungible token

    Returns FungiblePostCondition

makeContractNonFungiblePostCondition

  • Generates a non-fungible token post condition with a contract principal

    Returns a non-fungible token post condition object

    Parameters

    • address: string

      the c32check address

    • contractName: string

      the name of the contract

    • conditionCode: NonFungibleConditionCode

      the condition code

    • assetInfo: string | AssetInfo

      asset info describing the non-fungible token

    • assetName: ClarityValue

      asset name describing the non-fungible token

    Returns NonFungiblePostCondition

makeContractSTXPostCondition

  • makeContractSTXPostCondition(address: string, contractName: string, conditionCode: FungibleConditionCode, amount: BigNum): STXPostCondition
  • Generates a STX post condition with a contract principal

    Returns a STX post condition object

    Parameters

    • address: string

      the c32check address of the contract

    • contractName: string

      the name of the contract

    • conditionCode: FungibleConditionCode

      the condition code

    • amount: BigNum

      the amount of STX tokens

    Returns STXPostCondition

makeRandomPrivKey

makeSTXTokenTransfer

makeSigHashPreSign

  • makeSigHashPreSign(curSigHash: string, authType: AuthType, fee: BigNum, nonce: BigNum): string

makeStandardFungiblePostCondition

  • makeStandardFungiblePostCondition(address: string, conditionCode: FungibleConditionCode, amount: BigNum, assetInfo: string | AssetInfo): FungiblePostCondition
  • Generates a fungible token post condition with a standard principal

    Returns a fungible token post condition object

    Parameters

    • address: string

      the c32check address

    • conditionCode: FungibleConditionCode

      the condition code

    • amount: BigNum

      the amount of fungible tokens

    • assetInfo: string | AssetInfo

      asset info describing the fungible token

    Returns FungiblePostCondition

makeStandardNonFungiblePostCondition

  • Generates a non-fungible token post condition with a standard principal

    Returns a non-fungible token post condition object

    Parameters

    • address: string

      the c32check address

    • conditionCode: NonFungibleConditionCode

      the condition code

    • assetInfo: string | AssetInfo

      asset info describing the non-fungible token

    • assetName: ClarityValue

      asset name describing the non-fungible token

    Returns NonFungiblePostCondition

makeStandardSTXPostCondition

  • makeStandardSTXPostCondition(address: string, conditionCode: FungibleConditionCode, amount: BigNum): STXPostCondition
  • Generates a STX post condition with a standard principal

    Returns a STX post condition object

    Parameters

    • address: string

      the c32check address

    • conditionCode: FungibleConditionCode

      the condition code

    • amount: BigNum

      the amount of STX tokens

    Returns STXPostCondition

makeUnsignedContractCall

makeUnsignedSTXTokenTransfer

nextSignature

nextVerification

noneCV

omit

  • omit<T, K>(obj: T, prop: K): Omit<T, K>

parseAssetInfoString

  • parseAssetInfoString(id: string): AssetInfo
  • Parse a fully qualified string that identifies the token type.

    example

    "SP13N5TE1FBBGRZD1FCM49QDGN32WAXM2E5F8WT2G.example-contract::example-token"

    Parameters

    • id: string

      String in the format {address}.{contractName}::{assetName}

    Returns AssetInfo

parsePrincipalString

  • Parses a principal string for either a standard principal or contract principal.

    example

    "SP13N5TE1FBBGRZD1FCM49QDGN32WAXM2E5F8WT2G.example-contract"

    example

    "SP13N5TE1FBBGRZD1FCM49QDGN32WAXM2E5F8WT2G"

    Parameters

    • principalString: string

      String in the format {address}.{contractName}

    Returns StandardPrincipal | ContractPrincipal

Const parseReadOnlyResponse

parseRecoverableSignature

  • parseRecoverableSignature(signature: string): { r: string; recoveryParam: number; s: string }

parseToCV

  • Convert string input to Clarity value based on contract ABI data. Only handles Clarity primitives and buffers. Responses, optionals, tuples and lists are not supported.

    Parameters

    • input: string

      string to be parsed into Clarity value

    • type: ClarityAbiType

      the contract function argument object

    Returns ClarityValue

    returns a Clarity value

privateKeyToString

pubKeyfromPrivKey

publicKeyFromBuffer

publicKeyFromSignature

publicKeyToAddress

publicKeyToString

responseErrorCV

responseOkCV

Const rightPadHexToLength

  • rightPadHexToLength(hexString: string, length: number): string

serializeAddress

  • serializeAddress(address: Address): Buffer

serializeAssetInfo

  • serializeAssetInfo(info: AssetInfo): Buffer

serializeCV

serializeLPList

serializeLPString

serializeMemoString

  • serializeMemoString(memoString: MemoString): Buffer

serializeMessageSignature

serializeMultiSigSpendingCondition

serializePostCondition

serializePrincipal

serializePublicKey

serializeSingleSigSpendingCondition

serializeSpendingCondition

serializeStacksMessage

serializeTransactionAuthField

signWithKey

someCV

sponsorTransaction

standardPrincipalCV

standardPrincipalCVFromAddress

Const stringAsciiCV

Const stringUtf8CV

Const trueCV

tupleCV

  • tupleCV<T>(data: TupleData<T>): TupleCV<TupleData<T>>

Const txidFromData

  • txidFromData(data: Buffer): string

Const uintCV

  • uintCV(value: string | number | Buffer): UIntCV

validateContractCall

Const validateStacksAddress

  • validateStacksAddress(stacksAddress: string): boolean

Generated using TypeDoc