> For the complete documentation index, see [llms.txt](https://docs.leather.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.leather.io/developers/stacks-methods/stx_deploycontract.md).

# stx\_deployContract

Deploy a Clarity smart contract on the Stacks blockchain.

## Method name

`stx_deployContract`

The app must be connected first, through [`getAddresses`](/developers/methods/getaddresses.md). Leather deploys the contract from the account the app connected with.

## Parameters

| Parameter           | Description                                                                         | Required | Type               |
| ------------------- | ----------------------------------------------------------------------------------- | -------- | ------------------ |
| `name`              | Contract name                                                                       | ✅        | `string`           |
| `clarityCode`       | Clarity contract code                                                               | ✅        | `string`           |
| `clarityVersion`    | Clarity version. When omitted, Leather passes no version to the transaction builder | ❌        | `number`           |
| `postConditions`    | Post-conditions, each a hex-encoded serialized post-condition                       | ❌        | `string[]`         |
| `postConditionMode` | `allow`, `deny` or `originator`                                                     | ❌        | `string`           |
| `network`           | Network identifier                                                                  | ❌        | `string`           |
| `fee`               | Transaction fee in micro-STX. The user can change it before approving               | ❌        | `number \| string` |
| `nonce`             | Transaction nonce. The user can change it before approving                          | ❌        | `number \| string` |
| `sponsored`         | Build a sponsored transaction. Leather returns it signed, without a `txid`          | ❌        | `boolean`          |

## Example request

```typescript
try {
  const response = await window.LeatherProvider.request("stx_deployContract", {
    name: "my-smart-contract",
    clarityCode: "(define-public (say-hi) (ok \"Hello, world!\"))",
    clarityVersion: 2,
  });

  console.log("Transaction ID:", response.result.txid);
} catch (error) {
  console.log("Request error:", error.error.code, error.error.message);
}
```

## Example response

```json
{
  "jsonrpc": "2.0",
  "id": "d70e6f71-3ecf-4c4d-b555-80d1e4102d01",
  "result": {
    "txid": "1234abcd5678ef90123456789abcdef0123456789abcdef0123456789abcdef",
    "transaction": "<signed transaction hex>"
  }
}
```

## Errors

| Code     | Message                                                                 | When                         |
| -------- | ----------------------------------------------------------------------- | ---------------------------- |
| `16`     | `Wallet no longer available. Reconnect the app to an available wallet.` | The origin is not connected  |
| `-32602` | Parameter validation details                                            | A parameter fails validation |
| `4001`   | `User rejected request`                                                 | The user closes the window   |
