APIs

Developer Docs

stx_deployContract API method

May 21, 2025

Disclaimer: Leather does not validate smart contract logic or offer deployment guarantees. Developers are responsible for testing and auditing their contracts before deploying.

Publish a new Clarity smart contract to the Stacks blockchain via the user's Leather wallet.

Method name

stx_deployContract

Parameters

  • name (string, required): The name to assign to the deployed contract.

  • clarityCode (string, required): The full source code of the Clarity contract.

  • clarityVersion (number, optional): The version of the Clarity language to use. Defaults to 3 if not specified.

Usage

This method creates and broadcasts a contract deployment transaction using the user’s connected Leather wallet. Once confirmed, the smart contract becomes available on the specified network with the specified name.

Use this method to streamline contract deployment from within your dApp or developer tooling.

Use case

Use stx_deployContract when:

  • Deploying a new smart contract directly from a web-based IDE or builder interface

  • Enabling power users to launch DAO, NFT, or token contracts via an app UI

  • Facilitating Clarity experimentation from testnet tools

Security notes

  • The user must approve the deployment in Leather before it is signed and broadcast.

  • Malformed Clarity code or duplicate contract names at the same address will result in failed transactions.

  • Validate the syntax and simulate the contract first if possible to catch issues early.

Example

const response = await window.LeatherProvider.request("stx_deployContract", {
  name: "my-smart-contract",
  clarityCode: "(define-public (say-hi) (ok \"Hello, world!\"))",
  clarityVersion: 2,
});
{
  "jsonrpc": "2.0",
  "id": "d70e6f71-3ecf-4c4d-b555-80d1e4102d01",
  "result": {
    "txid": "0x1234abcd5678ef90123456789abcdef0123456789abcdef0123456789abcdef",
    "transaction": "0xf86a808504a817c80083015f90..."
  }
}