Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

storeCodeAndInstantiate

Upload a Wasm code blob and instantiate it in a single transaction. Returns the derived contract address.

Signature

function storeCodeAndInstantiate(
  client: Client<Signer>,
  parameters: {
    sender: Address
    codeHash: Hex
    msg: Json
    salt: Uint8Array
    funds?: Funds
    code: Base64
    admin?: Address
    typedData?: TypedDataParameter
  },
): Promise<[string, { hash: Uint8Array } & TxData]>

Example

import { createSignerClient, createTransport, testnet, PrivateKeySigner } from "@left-curve/sdk"
import { encodeBase64 } from "@left-curve/encoding"
import { readFileSync } from "node:fs"
import { sha256 } from "@left-curve/crypto"
import type { Address } from "@left-curve/sdk"
 
const client = createSignerClient({
  chain: testnet,
  transport: createTransport(),
  signer: PrivateKeySigner.fromMnemonic(process.env.DANGO_MNEMONIC!),
})
const sender: Address = "0x1234567890abcdef1234567890abcdef12345678"
 
const wasm = readFileSync("./contract.wasm")
const codeHash = `0x${Buffer.from(sha256(wasm)).toString("hex")}` as `0x${string}`
 
const [address, receipt] = await client.storeCodeAndInstantiate({
  sender,
  code: encodeBase64(wasm),
  codeHash,
  msg: { initialValue: "0" },
  salt: new TextEncoder().encode("counter-v1"),
})

Parameters

senderAddress. The deployer.

codeHashHex. SHA-256 of the Wasm. Must match the hash of the bytes you upload.

msgJson. Init message.

saltUint8Array. Deterministic salt.

fundsFunds, optional. Coins to send into the new contract.

codeBase64. Base64-encoded Wasm bytecode.

adminAddress, optional. Migration admin.

typedDataTypedDataParameter, optional.

Returns

[address, receipt] — the derived contract address and the broadcast receipt.

See also