Methods
The Clarinet JS SDK provides several methods that can be used to interact with simnet.
Installation
getAccounts
Retrieve a list of all Stacks addresses configured within the project, including wallets, deployers, and faucets.
getAssetsMap
Retrieve a list of asset balances associated with Stacks addresses, including fungible and non-fungible tokens.
getDataVar
Get the value of a data-var defined in a contract.
Parameters
contractRequiredstring
The contract identifier of the contract.
Example:counterdataVarRequiredstring
The name of the data-var for the contract.
countgetMapEntry
Get the value of a map entry by its key. Note that this method will always return an optional value some or none, just like Clarity map-get?.
Parameters
contractRequiredstring
The contract identifier of the contract.
Example:poolmapNameRequiredstring
The name of the map within the contract.
Example:ParticipantsmapKeyRequiredClarityValue
The key to access the value in the map.
Example:Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5')callReadOnlyFn
Call read-only functions exposed by a contract.
This method returns an object with the result of the function call as a ClarityValue. It takes function arguments in the form of Clarity values, which are available in the package @stacks/transactions.
Parameters
contractRequiredstring
The contract identifier of the contract.
Example:poolmethodRequiredstring
The name of the read-only function within the contract.
Example:get-participantargsRequiredClarityValue[]
The arguments to pass to the read-only function. If no arguments are needed, pass an empty array.
Example:[Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5')]senderRequiredstring
The Stacks address of the sender.
Example:ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGMcallPublicFn
Call public functions exposed by a contract.
This method returns an object with the result of the function call as a ClarityValue and the events fired during the function execution. It takes function arguments in the form of Clarity values, which are available in the package @stacks/transactions.
This method will simulate a block being mined and increase the block height by one.
Parameters
contractRequiredstring
The contract identifier of the contract.
Example:poolmethodRequiredstring
The name of the public function within the contract.
Example:register-participantargsRequiredClarityValue[]
The arguments to pass to the public function. If no arguments are needed, pass an empty array.
Example:[Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5')]senderRequiredstring
The Stacks address of the sender.
Example:ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGMtransferSTX
Transfer STX from one address to another. The amount transferred is in uSTX.
This method will simulate a block being mined and increase the block height by one.
Parameters
amountRequirednumber | bigint
The amount of uSTX to transfer.
1000000 equals 1 STXrecipientRequiredstring
The Stacks address of the recipient.
Example:ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5senderRequiredstring
The Stacks address of the sender.
Example:ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGMdeployContract
Deploy a contract to simnet.
This method will simulate a block being mined and increase the block height by one.
Parameters
nameRequiredstring
The name of the contract to be deployed.
Example:hello-worldcontentRequiredstring
The Clarity source code (or content) of the contract.
Example:(define-read-only (say-hi) (ok "Hello World"))optionsDeployContractOptions | null
An object to specify options, such as the Clarity version.
Example:{ clarityVersion: 2 } | nullsenderRequiredstring
The Stacks address of the sender.
Example:ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGMmineBlock
The callPublicFn, transferSTX, and deployContract methods all mine one block with only one transaction. It can also be useful to mine a block with multiple transactions.
This is what mineBlock is for.
This method takes an array of transaction objects. The transactions can be built with the tx helper exported by the SDK.
The tx helper has three methods:
callPublicFntransferSTXdeployContract
These methods have the same interface as simnet methods but instead of performing a transaction, they will build a transaction object that can be passed to the mineBlock function.
Parameters
txsRequiredTx[]
An array of transactions to be included in the block.
Example:[tx.transferSTX(100, recipient, sender), ...]mineEmptyBlock
Mine one empty block and increase the block height by one.
Returns the new block height.
mineEmptyBlocks
Mine multiple empty blocks to reach a certain block height.
Returns the new block height.
Parameters
countnumber
The number of empty blocks to mine. This parameter is optional.
Example:5runSnippet
Execute arbitrary Clarity code directly, which allows you to test and interact with smart contract functions without deploying them.
Parameters
snippetRequiredstring
The Clarity code snippet to be executed.
Example:(define-read-only (get-balance) (ok stx-balance))getContractsInterfaces
Returns the interfaces of the project contracts as a Map of Contracts, with the keys being the contract addresses.
These interfaces contain information such as the available functions, data-vars, maps, NFTs, and FTs defined in the contract.
getContractSource
Get the source code of a contract as a string.
Parameters
contractRequiredstring
The identifier of the contract for which the source code is requested.
Example:poolgetContractAST
Get the full AST (Abstract Syntax Tree) of a Clarity contract.
This method throws an error if it fails to get the AST or to encode it.
Parameters
contractIdRequiredstring
The identifier of the contract for which the AST (Abstract Syntax Tree) is requested.
Example:pool