Methods
The Clarinet SDK provides several methods that can be used to interact with the simnet.
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, providing a clear overview of asset distribution.
getDataVar
Get the value of a data-var
defined in a contract.
Parameters
contract
Requiredstring
The contract identifier of the contract.
Example:"counter"
dataVar
Requiredstring
The name of the data-var
for the contract.
"count"
getMapEntry
Get the value of a map entry by its key. Note that it will always return an optional value some
or none
, just like Clarity map-get?
.
Parameters
contract
Requiredstring
The contract identifier of the contract.
Example:"pool"
mapName
Requiredstring
The name of the map within the contract.
Example:"Participants"
mapKey
RequiredClarityValue
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, available in the package @stacks/transactions
.
Parameters
contract
Requiredstring
The contract identifier of the contract.
Example:"pool"
method
Requiredstring
The name of the read-only function within the contract.
Example:"get-participant"
args
RequiredClarityValue[]
The arguments to pass to the read-only function. If no arguments are needed, pass an empty array.
Example:[Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5')]
sender
Requiredstring
The Stacks address of the sender.
Example:'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
callPublicFn
Call public functions exposed by a contract.
This method returns an object with the result of the function call as a Clarity Value and the events fired during the function execution. It takes function arguments in the form in Clarity Values, available in the package @stacks/transactions
.
It will simulate a block being mined and increase the block height by one.
Parameters
contract
Requiredstring
The contract identifier of the contract.
Example:"pool"
method
Requiredstring
The name of the public function within the contract.
Example:"register-participant"
args
RequiredClarityValue[]
The arguments to pass to the public function. If no arguments are needed, pass an empty array.
Example:[Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5')]
sender
Requiredstring
The Stacks address of the sender.
Example:'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
transferSTX
Transfer STX from an address to an other. The amount is in uSTX
.
It will simulate a block being mined and increase the block height by one.
Parameters
amount
Requirednumber | bigint
The amount of uSTX
to transfer.
1000000, ie 1 STX
recipient
Requiredstring
The Stacks address of the recipient.
Example:'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5'
sender
Requiredstring
The Stacks address of the sender.
Example:'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
deployContract
Deploy a contract to the Simnet.
It will simulate a block being mined and increase the block height by one.
Parameters
name
Requiredstring
The name of the contract to be deployed.
Example:'hello-world'
content
Requiredstring
The Clarity source code (or content) of the contract.
Example:'(define-read-only (say-hi) (ok "Hello World"))'
options
DeployContractOptions | null
An object to specify options, such as the Clarity version.
Example:{ clarityVersion: 2 }
sender
Requiredstring
The Stacks address of the sender.
Example:'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
mineBlock
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.
It take an array of transaction objects. The transactions can be built with the tx
helper exported by the SDK.
The tx
helper has three methods
callPublicFn
transferSTX
deployContract
These methods have the same interface as the Simnet methods but instead of performing a transaction, it will build a transaction object than can be passed to the mineBlock
function.
Parameters
txs
RequiredTx[]
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
count
number
The number of empty blocks to mine. This parameter is optional.
Example:5
runSnippet
Execute arbitrary Clarity code directly, allowing to test and interact with smart contract functions without deploying them.
Parameters
snippet
Requiredstring
The Clarity code snippet to be executed.
Example:'(define-read-only (get-balance) (ok stx-balance))'
Last updated on