SDK Reference
The Clarinet JS SDK provides a comprehensive suite of helpers for testing and interacting with Clarity smart contracts. From simnet initialization to contract deployment, the SDK streamlines your entire testing workflow.
Initialize a simulated network:
initSimnetManage contract state:
getDataVar,getMapEntryCall contract functions:
callReadOnlyFn,callPublicFnTransfer STX:
transferSTXDeploy contracts:
deployContractMine blocks:
mineBlock,mineEmptyBlockCustom assertions:
toBeOk,toBeErr
Installation
npm install @stacks/clarinet-sdkInitialize simulated network
initSimnet
initSimnet initializes a simulated network for testing your smart contracts.
Usage:
initSimnet(manifestPath?: string): Promise<Simnet>manifestPath
string
Optional path to Clarinet.toml manifest file
Simnet properties
blockHeight
Returns the current block height of simnet.
deployer
Returns the default deployer address as defined in the project file.
You can also update the deployer:
currentEpoch
Returns the current epoch of simnet (e.g., 2.5 for Stacks 2.5).
Account management
getAccounts
getAccounts retrieves all configured Stacks addresses including wallets, deployers, and faucets.
Usage:
Asset balances
getAssetsMap
getAssetsMap retrieves asset balances for all addresses, including STX, fungible, and non-fungible tokens.
Usage:
Read contract state
getDataVar
getDataVar retrieves the value of a data variable from a contract.
Usage:
contract
string
Contract identifier
dataVar
string
Name of the data variable
getMapEntry
getMapEntry retrieves a value from a contract map by its key.
Usage:
contract
string
Contract identifier
mapName
string
Name of the map
mapKey
ClarityValue
Key to look up
Call contract functions
callReadOnlyFn
callReadOnlyFn calls read-only functions without mining a block.
Usage:
contract
string
Contract identifier
method
string
Function name
args
ClarityValue[]
Function arguments
sender
string
Sender address
callPublicFn
callPublicFn calls public functions and mines a block.
Usage:
callPrivateFn
callPrivateFn calls private functions (testing only) and mines a block.
Usage:
Transfer STX
transferSTX transfers STX between addresses and mines a block.
Usage:
amount
number | bigint
Amount in microSTX
recipient
string
Recipient address
sender
string
Sender address
Deploy contracts
deployContract deploys a new contract to simnet and mines a block.
Usage:
name
string
Contract name
content
string
Clarity source code
options
object | null
Deployment options
sender
string
Deployer address
Block mining
mineBlock
mineBlock mines a block with multiple transactions.
Usage:
mineEmptyBlock
mineEmptyBlock mines an empty block and increases block height.
Usage:
mineEmptyBlocks
mineEmptyBlocks mines multiple empty blocks.
Usage:
Utility methods
runSnippet
runSnippet executes arbitrary Clarity code without deploying.
Usage:
getContractsInterfaces
getContractsInterfaces returns contract interfaces with function signatures and storage.
Usage:
getContractSource
getContractSource retrieves the source code of a deployed contract.
Usage:
getContractAST
getContractAST returns the Abstract Syntax Tree of a contract.
Usage:
Custom matchers
The SDK provides Vitest matchers for Clarity value assertions.
Response matchers
toBeOk
Asserts that a response is (ok <value>).
toBeErr
Asserts that a response is (err <value>).
toBeSome
Asserts that a response is (some <value>).
toBeNone
Asserts that a response is (none).
Value matchers
toBeBool
Asserts a boolean value.
toBeInt
Asserts a signed integer value.
toBeUint
Asserts an unsigned integer value.
toBeAscii
Asserts a string-ascii value.
toBeUtf8
Asserts a string-utf8 value.
toBePrincipal
Asserts a principal value.
toBeBuff
Asserts a buffer value.
toBeList
Asserts a list of Clarity values.
toBeTuple
Asserts a tuple value.
Type checking
toHaveClarityType
Checks that a value has the expected Clarity type.
Event matchers
toContainEqual
Asserts that an events array contains a specific event. This is useful for checking transaction events.
Last updated
Was this helpful?
