clarity-wallets
Skill2 starsChanged 31 days agoMITView on GitHub
Connect Stacks wallets (Leather, Xverse, Ledger) and call contracts from apps with @stacks/connect: contract calls, post-conditions, message signing. Use for frontend or dapp wallet integration.
- Installs packages
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- clarity-apisSkill
- clarity-assetsSkill
- clarity-auditorSkill
- clarity-bitcoin-proofsSkill
- clarity-deploymentSkill
- clarity-ecosystemSkill
- clarity-environmentsSkill
- clarity-epochsSkill
- clarity-fuzzingSkill
- clarity-governanceSkill
- clarity-optimizerSkill
- clarity-oraclesSkill
- clarity-protocolsSkill
- clarity-scholarSkill
- clarity-securitySkill
- clarity-sip-complianceSkill
- clarity-stakingSkill
- clarity-startSkill
- clarity-system-integrationSkill
- clarity-testingSkill
- clarity-upgradesSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Use @stacks/connect 8 connect() and request() for new integrations.
- Distinctive: line 37
Use the wallet's official website for downloads.
- Very specific: line 57
Call connect()/request() only from user events, in client code, not during rendering or server-side rendering.
- Very specific: line 59
Use checksum-aware decoding before network/version and principal-shape checks.
- Distinctive: line 73
Keep the txid and returned block identity, recheck them for reorgs and apply the app's confirmation policy before irreversible effects.
- Very specific: line 90
After validating inputs and aggregating outflows, pass address.contract and the native token name separately …
- Very specific: line 114
Use Deny when the required flows can be bounded.
- Distinctive: line 121
When settling accrued entitlement into storage on ownership change, preserve the prior owner's rewards, checkpoint exactly once and clear …
- Distinctive: line 127
Test no rewards, rewards for either/both endpoints, changing rewards between quote and execution, multiple payouts, refund round trips and …
- Distinctive: line 142
Read references/examples.md when writing these requests: complete deployment, message-signing and WalletConnect examples.
- Distinctive: line 162
Do not downgrade Clarity or remove post-conditions to make a device accept a transaction.
- Very specific: line 164
Read references/ledger.md before a hardware wallet signs a deployment, a versioned or multisig payload, or many post-conditions.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clarity Wallets
Key distinctions
- Use
@stacks/connect8connect()andrequest()for new integrations.UserSession,showConnect,openContractCalland@stacks/connect-reactare legacy. - Validate C32 checksums, network and principal shape. Contract IDs require exactly
address.name, not a bare account; a postcondition builder returning an object does not prove validity. Native multisig usesSM/SN; address length varies. - A cached address or
isConnected()is not proof of account ownership, current wallet network or transaction approval. - Connect 8 uses
contract: "ADDRESS.name",functionArgsand lowercasetxid. Legacy callbacks and direct wallet APIs differ. cvToStringprints Clarity syntax. UseCl.serializefor wire hex, or let Connect serializeClvalues.- Wallet, Ledger app, transport and node support are independent. A consensus-valid transaction can exceed the signer's capacity: check device model, app version, serialized transaction size, post-condition count and Clarity payload support.
- A deployment request's
clarityVersioncan be rewritten by a wallet. Inspect the payload and verify the deployed language version. - STX/FT postconditions count gross outflows per principal/asset, not net spend or recipient receipts.
- Wallet signing/broadcast is separate from successful execution: verify a successful mined receipt and apply the app's confirmation policy.
Choose the interface
| Need | Start here |
| Browser dapp supporting several Stacks wallets | @stacks/connect |
| Clarity values, post-conditions, unsigned transaction construction | @stacks/transactions |
| Xverse-specific Stacks, Bitcoin or mobile behavior | sats-connect, including its own response envelope |
| Mobile pairing | Connect's optional WalletConnect provider; verify the selected wallet's supported chain/methods |
| Ledger signing transport | @zondax/ledger-stacks, plus device checks |
| Native multisig signing | Governance; inspect stx-labs/multisig-cli for Ledger signing workflows |
- Connect 8.2.7's selector includes Leather, Xverse, Asigna and Fordefi.
- Use the wallet's official website for downloads. Follow current documentation links rather than copying browser-store identifiers from old tutorials.
- Current protocol contracts/addresses belong in protocols, not wallet configuration examples.
Connect and call
// fragment: Connect 8.2.7 contract call with a Deny post-condition (imports from @stacks/connect, @stacks/transactions)
const { addresses } = await connect({ network });
const account = addresses.find(({ address }) => validateStacksAddress(address) &&
(network === 'mainnet' ? /^S[PM]/.test(address) : /^S[TN]/.test(address)));
if (!account) throw new Error('No Stacks account for the intended network');
const result = await request('stx_callContract', {
contract, functionName: 'deposit', functionArgs: [Cl.uint(amount)], network, // contract: `${string}.${string}`
address: account.address, postConditionMode: 'deny',
postConditions: [Pc.principal(account.address).willSendEq(amount).ustx()],
});
if (!result.txid) throw new Error('Wallet returned no broadcast transaction ID');
return result.txid; // track canonical execution separately- Call
connect()/request()only from user events, in client code, not during rendering or server-side rendering.connect()opens the wallet selector; existing sessions can request fresh addresses withrequest('stx_getAddresses', { network })where supported. - Select the Stacks address by chain and intended account, never a fixed index in a mixed BTC/STX address array. If several eligible Stacks accounts come back, choose explicitly (the fragment takes the first).
- Use checksum-aware decoding before network/version and principal-shape checks.
validateStacksAddresschecks the address component only; validate contract names separately. C32 addresses vary in length (ST000000000000000000002AMW42His valid), andSM/SNare native multisig accounts, not contract principals. Decoding proves neither ownership nor authorization. addressis a recommendation; wallets may ignore it. Confirm origin, network and intended account in the wallet and the returned transaction.amountis micro-STX for STX; FT amounts use the asset's base units. Keep integers asbigintor decimal strings, including values above JavaScript's safe integer range.- The example ABI is
(define-public (deposit (amount uint)) ...)transferring exactlyamountfrom its transaction sender. Adenycall needs a condition for every outgoing principal/asset (see post-conditions). Use the deployed ABI, the actual token asset name and the current protocol registry; a token contract name is not necessarily its asset name.
New dapp: install, button, status
npm install @stacks/connect@8.2.7 @stacks/transactions@7.6.0 and keep one deduped @stacks/transactions (npm ls @stacks/transactions). Pin packages in the project lockfile.
- API bases: mainnet
https://api.hiro.so, testnethttps://api.testnet.hiro.so, devnethttp://localhost:3999(clarinet devnet start). - Disable the button while a request is in flight (one request per click), catch wallet rejection or failure and do not auto-retry. Re-enable it in
finallyonly if no txid came back; once one does, show the transaction as pending, because another click can send a second one. A Leather multisig account returnsstatus: 'proposed'and aproposalIdinstead of a txid: checkstatusbefore the txid check in Connect and call, keep the button disabled and show the proposal as awaiting co-signers. - Poll
/extended/v3/transactions/{tx_id}: v3 returns the canonical mined record or the mempool record and has nocanonicalflag. Read the status poller before writing your own. - Report success only for
status: "success"withblock.heightandblock.index_hash. Mined records can also beabort_by_response,abort_by_post_conditionorproblematic_skipped(epoch 4.0): failures, not pending. - A 404 is normal right after broadcast and after a drop: v3 never reports
dropped_*(the deprecated/extended/v1/tx/{tx_id}still does). No 404, timeout or lookup error proves failure: a dropped transaction can reappear or still be mined, so resume lookup and never automatically re-sign. - Keep the txid and returned block identity, recheck them for reorgs and apply the app's confirmation policy before irreversible effects. Sources: v3 lookup, canonical query, v1 dropped lookup.
- Test the same code against devnet (devnet runbook); the wallet must support a custom node, so for automated checks use the scripted flow in clarity-deployment. Test the actual supported wallet/device combination, including rejection, account/network changes, large values, post-conditions, sponsorship and pending transactions where used.
- Pending, dropped, reverted and canonical-success evidence: clarity-apis.
Post-conditions
- Standard STX/FT amount conditions constrain the total sent by one principal for one native asset in the whole transaction. They do not identify recipients, individual calls or net balance changes. This aggregate-outflow rule applies in every coverage mode;
Originatorchanges coverage, not amount semantics. - Incoming transfers do not offset outgoing ones: a wallet that sends 100 and receives a 40 refund sent 100, so constrain wallet sent = 100, not 60, and in
Denymode also cover the refunding principal's 40. STX amount checks include STX burned; fees are separate. - Two conditions on the same principal and asset constrain the same total: a reward contract paying Alice 3 and Bob 7 of one FT sent 10, so conditions for 3 and 7 both fail; they do not select separate payouts. Use one condition for 10.
- Even sent = 10 does not prove Alice received 3. Enforce recipient and minimum output in the contract; for a balance-delta check, select the actual spendable asset and account for other movements within the measured scope.
- Use the native asset the call moves, not a token symbol or interface name. A wrapper whose
transfercallsstx-transfer?, such as Zest wSTX, moves STX: an FT condition on the wrapper sees nothing sent, even if it declares an FT. Write STX conditions in the micro-STX it moves, which differs from the call amount when the wrapper rescales it. - FT and NFT identity is
address.contract-name::asset-name. Require exactly one dot in the contract ID, a valid address and contract name and the actual declared asset name; reject bare accounts and extra components (FT recipe). - An NFT condition also names the key's exact Clarity value, never a recipient. A wrong name, key type or key value matches nothing, so
willSendAsset()aborts andwillNotSendAsset()passes, protecting nothing. A burn counts as a send. When a call may or may not move the NFT, usewillMaybeSendAsset()(SIP-040MAY SEND, epoch 3.4+): it passes either way and still covers the NFT inDenyandOriginatormode. - An SFT that keeps balances only in a map is invisible to post-conditions: tell the developer. A SIP-013 mirrored SFT burns the sender's tag NFT (SIP key
{token-id: uint, owner: principal}) on transfer, so pair the FT amount condition withwillSendAsset()on that tag. The tag condition binds the ID; without itDenymode aborts, as doesOriginatormode when the sender is the origin. If the contract also burns an existing recipient's tag, as SIP-013's example does,Denymode needsPc.principal(recipient).willMaybeSendAsset()on that tag, because that burn is the recipient's send. Read the SFT helpers before writing these conditions.
Build an FT condition
- After validating inputs and aggregating outflows, pass
address.contractand the native token name separately (Pc.principal(sender).willSendEq(amount).ft(contractId, assetName)). Do not append the token name to the contract ID.
import { Pc } from '@stacks/transactions';
export function ftOutflow(sender, amount, token) {
return Pc.principal(sender).willSendEq(amount)
.ft(token.contractId, token.assetName);
}- Assert
condition.assetequalstoken.contractId + '::' + token.assetName, along with sender, amount, comparator and coverage mode. A contract name can differ from its native token name. - With Stacks.js 7, serialize via
postConditionToHex(condition)and decode viaPc.fromHex(hex); assert the complete round trip matches the intended condition. Successful construction alone is insufficient.
Choose coverage deliberately
| Mode | Uncovered outflows | Explicit conditions |
Deny | Rejected for every sending principal | All must pass |
Originator | Rejected only for the transaction origin account | All must pass, including conditions on contracts |
Allow | Permitted | All supplied conditions still must pass |
Originatoris available from epoch 3.4 (SIP-040). Its origin is fixed by transaction authorization, including sponsorship;as-contract?does not change it. It does not protect a user's vault/contract principal or guarantee incoming assets; constrain those principals explicitly. Verify node, SDK, wallet and device support before using it.- For complex routes,
Originatorcan protect origin outflows without enumerating every contract movement; preserve protocol authorization and scoped allowances. - Use
Denywhen the required flows can be bounded. Never silently fall back toAllow, remove conditions or widen amounts until signing succeeds. - Stakes and unstakes need Staking/PoX conditions, not STX ones.
Design predictable reward flows
- Automatic reward harvests inside token transfers, swaps or deposits can add outflows to several recipients from the same reward contract, and pending rewards, fees and configuration can change before inclusion. Enumerate
(sender, asset, total)across the whole call graph (both endpoints' hooks, routers, fees, refunds), or settle entitlement into storage and pay through an explicit claim. - Known batches remain usable with aggregate bounds.
- When settling accrued entitlement into storage on ownership change, preserve the prior owner's rewards, checkpoint exactly once and clear paid entitlement; test repeated saves/claims and migrations.
- Separate claims cost another transaction and lose atomic settlement with the original action. Keep atomic composition where required and enforce recipient, min-output, max-input, fee and deadline bounds on-chain.
- A frontend preflight is advisory and can become stale. Stacks transaction postconditions are not arbitrary before/after assertions over contract state; see state-only authority abuse.
Test the signed policy
- Test no rewards, rewards for either/both endpoints, changing rewards between quote and execution, multiple payouts, refund round trips and wrong recipients with unchanged gross totals.
- Submit the intended mode and conditions explicitly in tests: simnet disables checks when both are omitted (simulator traps).
- Assert committed balances, entitlement, events and rollback. Test the actual wallet's request encoding and displayed limits separately.
Sources: released node's condition evaluator, asset accumulation, SIP-040, postcondition documentation.
Messages, deployments and sessions
- Plain text signature:
request('stx_signMessage', { message })uses a wallet-specific prefix and is not for contracts; bind it to your own challenge (for example a nonce). SIP-018 structured data:request('stx_signStructuredMessage', { message: Cl.tuple(...), domain: Cl.tuple({ name, version, 'chain-id' }) })withchain-idmainnetu1, testnetu2147483648; results carrysignatureandpublicKey. Use SIP-018 structured signatures when the protocol requires them. Examples: mobile, sessions and messages. - For backend authentication, verify a wallet signature over a server-issued, single-use challenge bound to the intended domain and expiration. For contract-verified SIP-018 messages, verify the exact domain, chain, schema and replay protection (security).
- Deployment:
request('stx_deployContract', { name, clarityCode, clarityVersion, network, postConditionMode: 'deny', postConditions: [] })(deployment request).nameis the contract name, notADDRESS.name; the signing origin's address deploys. An empty list is only right when deployment performs no asset outflows. - Wallet methods can broadcast immediately; do not assume
broadcast: falseworks in every provider. For pre-broadcast payload inspection, use a supported sign-only flow and verify its actual behavior. Confirm the signed payload's contract name, source, language version, origin, chain ID, nonce, fee, sponsorship and post-conditions. - Leather emits an unversioned deployment when
clarityVersionis omitted or equals6, so the node's epoch default selects the language (implementation). A request for 6 is not a permanent wire-level pin: check the wallet release and the deployed version. Ordering and initialization: clarity-deployment. - Mobile:
connect({ walletConnect: { projectId, networks: [WalletConnect.Networks.Stacks] } });walletConnectProjectIdis deprecated in 8.2.7. WalletConnect is a connection protocol, not a wallet; a Bitcoin-capable mobile connection does not establish Stacks support. Test the in-app browser and external pairing independently. - Connect 8 caches every connected address, across networks, and exposes no portable account/network event listener; check provider-specific events and capabilities separately. Re-query after wallet, account or network changes and before building an action.
disconnect()clears local state and ends a WalletConnect session; it does not undo signed transactions or revoke contract permissions. - Read references/examples.md when writing these requests: complete deployment, message-signing and WalletConnect examples.
Sources: Connect request/type source, Xverse calls, Leather RPC source.
Compatibility traps
- Connect 8 call/deploy results use
txidand optionallytransaction; legacy callbacks usetxId/txRaw; direct Sats Connect wraps responses instatus,resultorerror. - Let Connect serialize
ClandPcobjects. Direct APIs may require hex viaCl.serialize(value)andpostConditionToHex(condition). - For STX through a token interface, pass the wrapper the target contract or protocol requires, since it rejects others; otherwise use Zest wSTX.
- Current Xverse docs support post-conditions for calls and deployments; do not repeat older tables claiming otherwise, and test the installed wallet.
- Connect's BTC
sendTransferadapter stripsnetworkfor Xverse/Fordefi. ItssignPsbtadapter can drop inputs without addresses,networkandallowedSighash; Leather receives signing indexes rather than the full input mapping. Inspect the final request when those fields matter. - SIP-030 method definitions do not guarantee implementation: a connection does not prove
stx_transferSip10Ft, sign-only, sponsorship or multisig support. Connect 8.2.7's selector (Leather, Xverse, Asigna, Fordefi) does not imply every RPC method. - Sponsorship: coordinate origin and sponsor nonce/signature stages explicitly and preserve the origin-signed fields.
- Native multisig must preserve pubkey order, threshold and the selected signing mode. A contract multisig approves contract state transitions instead; they are not interchangeable (clarity-governance).
Ledger and hardware signing
- Record wallet version, Ledger model/firmware, Stacks app version, JS transport version, Clarity version, network and serialized transaction bytes. Distinguish node rejection, transport failure, device parsing/display rejection and invalid signature;
Data invalidalone does not identify the cause. - Count serialized transaction bytes, including auth and post-conditions, not source or hex length: UTF-8 source bytes, hex characters and transaction bytes are different sizes. Rehearse the exact signing path on the intended device before fixing an immutable deployer identity.
- A chain-valid contract can exceed hardware limits. Consult versions for consensus bounds; never treat a device limit as one.
- Do not downgrade Clarity or remove post-conditions to make a device accept a transaction. Choose a supported signer/release path, or deliberately redesign and retest the protocol.
- Splitting a contract changes dependencies, principals, authorization and deployment order. Whitespace reduction also changes the exact source hash. Treat either as a reviewed release change.
- Read references/ledger.md before a hardware wallet signs a deployment, a versioned or multisig payload, or many post-conditions. Ledger does not reject every
VersionedSmartContract.
Lookup
- Connect source and issues, current wallet support.
- Leather docs, current source and issues. The former extension repo is archived.
- Xverse Sats Connect docs, SDK source and issues.
- Stacks.js source and issues, Ledger device app, Ledger JS client.
- Route Bitcoin proof work to clarity-bitcoin-proofs.
Reference baseline
Examples use Clarity 4+ syntax unless marked, checked on epoch 4.0. Source links in this skill use these pins; links into sibling skills use their owner's SKILL.md.
stacks-core: ccf31dc69c.stacks-connect: 096c3fa5a1.stacks-js-wallets: e6084a5214.sats-connect: 2e196801c0.leather-mono: c7f0371584.ledger-stacks: 3f9bc89ce7.ledgerhq-stacks: 3be06bebde.stacks-multisig-cli: 47bdc291a5.stacks-core-release: 10474cdec9.stacks-blockchain-api: ee0c0ac5be.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

