instantiate
Call v334 → current #8Creates a new contract instance from previously uploaded code.
View calls on chainCall Workflow
Click items to navigate. Pan and zoom to explore.
The Big Picture
Once code is uploaded (via upload_code or instantiate_with_code), you can create many contract instances from it without re-uploading. This is more gas-efficient and enables patterns like contract factories where one contract deploys others using known code hashes.
Why This Matters
Code upload is expensive (storage deposit). If you're deploying many instances of the same contract (e.g., one per user), upload once, then use instantiate repeatedly. Saves deposits and gas.
Example Scenario
You uploaded a multisig wallet contract earlier (code_hash=0xabc...). Now user Alice wants her own instance. Call instantiate with code_hash=0xabc..., data=constructor(alice_as_owner), salt=random. Instantiated fires with Alice's unique contract address.
Common Questions
- How do I get the code_hash?
- From the CodeStored event when code was uploaded, or by hashing the WASM yourself. Query CodeInfoOf to verify a hash exists on-chain.
- What if code_hash doesn't exist?
- Call fails with CodeNotFound error. Upload the code first using upload_code or instantiate_with_code.
- Is the address deterministic?
- Yes: hash(deployer, code_hash, input_data, salt). Same inputs = same address. Use this for counterfactual deployments.
Use Cases
- Deploy multiple instances of the same contract code
- Factory pattern - contracts creating contracts
- Efficient deployment when code already exists
- Upgrade patterns using known code hashes
From Chain Metadata
Instantiates a contract from a previously deployed wasm binary. This function is identical to [`Self::instantiate_with_code`] but without the code deployment step. Instead, the `code_hash` of an on-chain deployed wasm binary must be supplied.
Input Parameters
Permissions
Permission data inferred from metadata. May be incomplete.
Requirements
- Code with given code_hash exists in PristineCode
- Caller has sufficient balance for storage deposits
- Salt produces unique contract address
- Gas limit sufficient for constructor execution
Effects
Events Emitted
Storage Modified
Postconditions
- New contract instantiated at deterministic address
- Instantiated event emitted
- Contract constructor executed
- Storage deposit charged
Side Effects
- Contract state initialized by constructor
- Nonce incremented
- Code reference count updated
Code Examples
import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";
const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });
// Build instantiate call
const value = 0;
const gas_limit = 0 as any /* Weight */;
const storage_deposit_limit = 0 as any /* Option */;
const code_hash = 0 as any /* H256 */;
const data = 0;
const salt = 0;
const call = api.tx[stringCamelCase("Contracts")][stringCamelCase("instantiate")](
value,
gas_limit,
storage_deposit_limit,
code_hash,
data,
salt
);Runtime Info
- Pallet Index
- 29
- Call Index
- 8
- First Version
- v334
- Current Version
- v393