> ## Documentation Index
> Fetch the complete documentation index at: https://cosmos-docs-cosmjs-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Uploading Code

> Deploy Wasm binaries to a CosmWasm chain with optional access restrictions

Before you can instantiate a contract, the compiled Wasm binary must be uploaded to the chain. The `upload` method on `SigningCosmWasmClient` handles gzip compression, transaction signing, and returns a `codeId` you use for instantiation.

## Basic Upload

```typescript theme={"system"}
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import { readFileSync } from "fs";

const wallet = await DirectSecp256k1HdWallet.fromMnemonic("your mnemonic ...", {
  prefix: "osmo",
});
const [{ address }] = await wallet.getAccounts();

const client = await SigningCosmWasmClient.connectWithSigner(
  "https://rpc.my-chain.network",
  wallet,
  { gasPrice: GasPrice.fromString("0.025uosmo") },
);

const wasmCode = readFileSync("./my_contract.wasm");
const uploadResult = await client.upload(address, wasmCode, "auto");

const { codeId, checksum, originalSize, compressedSize, transactionHash } = uploadResult;
```

CosmJS automatically gzip-compresses the Wasm bytes before submitting the transaction. The `upload` method uses a tighter gas multiplier of 1.1x (instead of the default 1.4x) for `"auto"` fee estimation because code upload simulation is very accurate.

## Upload with Access Restrictions

You can restrict who is allowed to instantiate your uploaded code:

```typescript theme={"system"}
import { AccessConfig, AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";

const permission = AccessConfig.fromPartial({
  permission: AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES,
  addresses: [address],
});

const uploadResult = await client.upload(address, wasmCode, "auto", "optional memo", permission);
```

| AccessType                     | Description                               |
| ------------------------------ | ----------------------------------------- |
| `ACCESS_TYPE_EVERYBODY`        | Anyone can instantiate                    |
| `ACCESS_TYPE_ANY_OF_ADDRESSES` | Only the listed addresses can instantiate |

## Upload Result

The `UploadResult` contains everything you need to proceed with instantiation:

| Field             | Type      | Description                                             |
| ----------------- | --------- | ------------------------------------------------------- |
| `codeId`          | `number`  | The chain-assigned code ID for instantiation            |
| `checksum`        | `string`  | Hex-encoded SHA-256 of the original (uncompressed) Wasm |
| `originalSize`    | `number`  | Size of the original Wasm in bytes                      |
| `compressedSize`  | `number`  | Size of the gzip-compressed Wasm in bytes               |
| `transactionHash` | `string`  | Upper-case hex transaction hash                         |
| `height`          | `number`  | Block height of inclusion                               |
| `events`          | `Event[]` | Transaction events                                      |
| `gasWanted`       | `bigint`  | Gas requested                                           |
| `gasUsed`         | `bigint`  | Gas consumed                                            |

## Next Steps

<CardGroup cols={2}>
  <Card title="Instantiating Contracts" icon="plus" href="/cosmjs/v0.38.x/guides/cosmwasm/instantiating">
    Create contract instances from uploaded code.
  </Card>

  <Card title="Gas and Advanced Usage" icon="gauge-high" href="/cosmjs/v0.38.x/guides/cosmwasm/gas-and-advanced">
    Gas estimation, simulation, and fee configuration.
  </Card>
</CardGroup>
