1"use strict";(self.webpackChunkcosmwasm_documentation=self.webpackChunkcosmwasm_documentation||[]).push([["7764"],{2986(t,e,n){n.r(e),n.d(e,{metadata:()=>i,default:()=>u,frontMatter:()=>r,contentTitle:()=>a,toc:()=>l,assets:()=>c});var i=JSON.parse('{"id":"core/entrypoints/instantiate","title":"Instantiate","description":"This is one of the most fundamental entrypoints. This entrypoint is called once during the contract lifecycle,","source":"@site/docs/core/entrypoints/instantiate.md","sourceDirName":"core/entrypoints","slug":"/core/entrypoints/instantiate","permalink":"/core/entrypoints/instantiate","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1759504092000,"sidebarPosition":1,"frontMatter":{"sidebar_position":1},"sidebar":"tutorialSidebar","previous":{"title":"Entrypoints","permalink":"/core/entrypoints/"},"next":{"title":"Execute","permalink":"/core/entrypoints/execute"}}'),o=n(4848),s=n(8453);let r={sidebar_position:1},a="Instantiate",c={},l=[{value:"Definition",id:"definition",level:2}];function d(t){let e={admonition:"admonition",code:"code",h1:"h1",h2:"h2",header:"header",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...t.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(e.header,{children:(0,o.jsx)(e.h1,{id:"instantiate",children:"Instantiate"})}),"\n",(0,o.jsx)(e.p,{children:"This is one of the most fundamental entrypoints. This entrypoint is called once during the contract lifecycle,\nright after an address has been assigned. It essentially is there to initialise the state of your contract\n(for example, initialising a counter in storage, etc.). You can imagine it as the constructor of your contract."}),"\n",(0,o.jsx)(e.admonition,{type:"tip",children:(0,o.jsxs)(e.p,{children:["Note that this function is called for ",(0,o.jsx)(e.strong,{children:"each instance"})," of your contract that you decide to create, not one time ever.\nTo equate it to object-oriented programming, your contract is a ",(0,o.jsx)(e.strong,{children:"class"}),", and instantiate entrypoint\nis the ",(0,o.jsx)(e.strong,{children:"constructor"}),", and you can have ",(0,o.jsx)(e.strong,{children:"multiple instances"})," (objects) of the same class,\nand the constructor must be called exactly once for every one of these instances.\nIt is ",(0,o.jsx)(e.strong,{children:"NOT"})," a singleton class."]})}),"\n",(0,o.jsx)(e.h2,{id:"definition",children:"Definition"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-rust",metastring:'title="contract.rs"',children:'#[cfg_attr(not(feature = "library"), entry_point)]\npub fn instantiate(\n deps: DepsMut,\n env: Env,\n info: MessageInfo,\n msg: InstantiateMsg,\n) -> StdResult<Response> {\n // TODO: Put your initialization logic here.\n Ok(Response::new())\n}\n'})})]})}function u(t={}){let{wrapper:e}={...(0,s.R)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(d,{...t})}):d(t)}},8453(t,e,n){n.d(e,{R:()=>r,x:()=>a});var i=n(6540);let o={},s=i.createContext(o);function r(t){let e=i.useContext(s);return i.useMemo(function(){return"function"==typeof t?t(e):{...e,...t}},[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),i.createElement(s.Provider,{value:e},t.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.