stacks_contractCall
Request a Stacks contract function call.
pubkey
required - string
The stacks address of sender.
contractAddress
required - string
The STX address of the contract.
contractName
required - string
The name of the contract.
functionName
required - string
The name of the contract function to be called.
functionArgs
required - Array<ClarityValue>
An array of function arguments of ClarityValue type.
postConditions
optional - Array<PostCondition>
An array of post conditions to attach to the transaction.
postConditionMode
optional - PostConditionMode
The post condition mode to use. Defaults to PostConditionMode.Allow
.
anchorMode
optional - AnchorMode
The anchor mode to use. Defaults to AnchorMode.Any
.
nonce
optional - BigInt
Custom nonce to set for the transaction. Default value is the next nonce for the address.
version
optional - string
Version of parameter format.
const result = await client.request({
chainId: "stacks:1",
topic: session.topic, // Get this from the session approval
request: {
method: "stacks_contractCall",
params: {
pubkey: address,
postConditions,
contractAddress: "SP1H1733V5MZ3SZ9XRW9FKYGEZT0JDGEB8Y634C7R",
contractName: "my_contract_name",
functionName: "transfer",
functionArgs: [
uintCV("123"),
standardPrincipalCV("SP1BEEN4WP9YT42PR70FYSG6C3WFG54QJDEN0KWR"),
standardPrincipalCV("SP3F7GQ48JY59521DZEE6KABHBF4Q33PEYJ823ZXQ"),
noneCV(),
],
postConditionMode: PostConditionMode.Deny,
version: "1",
},
},
});
const txId = result.txId;
stacks_stxTransfer
Request a transfer of STX tokens.
pubkey
required - string
The stacks address of sender.
recipient
required - string
The STX address of the recipient.
amount
required - BigInt
Amount of STX tokens to transfer in microstacks.
memo
optional - string
Memo string to be included with the transfer transaction.
postConditions
optional - Array<PostCondition>
An array of post conditions to attach to the transaction.
postConditionMode
optional - PostConditionMode
The post condition mode to use. Defaults to PostConditionMode.Allow
.
version
optional - string
Version of parameter format.
const result = await client.request({
chainId: chain,
topic: session.topic,
request: {
method: "stacks_stxTransfer",
params: {
pubkey: address,
recipient: "SP3F7GQ48JY59521DZEE6KABHBF4Q33PEYJ823ZXQ",
amount: BigInt(1000),
},
},
});
const txId = result.txId;
stacks_signMessage
Request signing of an arbitrary message.
pubkey
required - string
The stacks address of sender.
message
required - string
Message payload to be signed.
version
optional - string
Version of parameter format.
const message = "loremipsum";
const result = await client.request({
chainId: chain,
topic: session.topic,
request: {
method: "stacks_signMessage",
params: {
pubkey: address,
message: message,
},
},
});
const publicKey = result.publicKey;
const signature = result.signature;
const valid = verifyMessageSignatureRsv({
message,
publicKey,
signature,
});
stacks_contractDeploy
Request a Clarity contract deployment
pubkey
required - string
The stacks address of sender.
contractName
required - string
The name the contract is to be deployed as.
codeBody
required - string
Body of the contract source code.
postConditions
optional - Array<PostCondition>
An array of post conditions to attach to the transaction.
postConditionMode
optional - PostConditionMode
The post condition mode to use. Defaults to PostConditionMode.Allow
.
version
optional - string
Version of parameter format.
const codeBody = `
;; hello-world
(define-read-only (echo-number (val int)) (ok val))
(define-public (say-hi) (ok "hello world"))
`
const result = await client.request({
chainId: chain,
topic: session.topic,
request: {
method: "stacks_contractDeploy",
params: {
pubkey: address,
contractName: "my_contract_name_1",
codeBody: codeBody,
postConditionMode: PostConditionMode.Allow,
},
},
});
const txId = result.txId;