Smart contracts can receive, store, and return data using native Rust types such as strings, integers, booleans, maps, and vectors. The SDK also provides types for values that need special handling at the contract boundary.
Contracts can store u64 and u128 values directly, but JSON consumers cannot always represent them without losing precision. Use the SDK’s U64 and U128 wrapper types for public inputs and outputs that need to be serialized as strings.
JavaScript numbers cannot represent every integer above 2^53 - 1. Keep native integer types in internal contract logic, and use the JSON wrapper types at the external interface when necessary.
Contracts can receive and return complex Rust structures. Objects used as JSON inputs or outputs need JSON serialization, while structures stored in contract state need Borsh serialization.
Use NearToken to represent NEAR amounts. It provides constructors and accessors for yoctoNEAR, millinear, and NEAR values.
let deposit = NearToken::from_near(1);let amount = deposit.as_yoctonear();
The SDK’s AccountId type validates NEAR account IDs when values enter the contract. Prefer it to a plain String whenever a value represents an account.
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"NEAR Docs","colors":{"primary":"#1fb858","light":"#1fb858","dark":"#1fb858"},"logo":{"light":"https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/logo.svg?fit=max\u0026auto=format\u0026n=qO2GD-gji1aakHqN\u0026q=85\u0026s=fe9551b1c3085e39a97965b2886dad4a","dark":"https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/logo_rev.svg?fit=max\u0026auto=format\u0026n=qO2GD-gji1aakHqN\u0026q=85\u0026s=1455d1ccc3385495e8b52e6657ce8c84"},"favicon":"https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/favicon.svg?fit=max\u0026auto=format\u0026n=qO2GD-gji1aakHqN\u0026q=85\u0026s=ef64e8324f93ca4f703d8ebad5e32c53","api":{"openapi":"openapi.json","playground":{"display":"interactive"},"examples":{"defaults":"all","languages":["bash","javascript","python"]}},"appearance":{"default":"system","strict":false},"navbar":{"links":[{"icon":"wallet","href":"https://wallet.near.org/","label":"Wallets"},{"icon":"search","href":"https://explorer.near.org/","label":"Explorers"},{"icon":"layout-grid","href":"https://nearcatalog.xyz/","label":"NEAR Catalog"}]},"search":{"prompt":"Search docs..."},"seo":{"metatags":{"google-site-verification":"x36GvqeIYFjDAl2NNFM-83XykcMYMLRY6f9lgUZbDpA"}},"fonts":{"family":"Inter"},"icons":{"library":"lucide"},"styling":{"eyebrows":"breadcrumbs","codeblocks":{"theme":{"light":"github-light","dark":"github-dark"}},"latex":true},"integrations":{"ga4":{"measurementId":"G-TMG0M3DPNW"}},"contextual":{"options":["copy","claude","cursor"],"display":"header"},"interaction":{"drilldown":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"neardocs","hasAudioNarration":false,"actualSubdomain":"neardocs","customDomains":["docs.near.org"],"gitSource":{"type":"github","owner":"near","repo":"docs","deployBranch":"master","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6adf8fac54a8cd69daa376f4","collectionId":"6082491f-4a49-43d4-8390-e1aeb4fc09f1","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6adf8fac54a8cd69daa376f4"},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6adf8fac54a8cd69daa376f4","clientVersion":"0.0.3990","searchFilterCounts":[{"language":"default","tag":"RPC","count":46},{"language":"default","tag":"Smart Contracts","count":44},{"language":"default","tag":"Protocol","count":30},{"language":"default","tag":"Building Smart Contracts","count":30},{"language":"default","tag":"Tokens \u0026 Primitives","count":21},{"language":"default","tag":"Tutorials","count":21},{"language":"default","tag":"Concepts","count":19},{"language":"default","tag":"Home","count":17},{"language":"default","tag":"Multi-Chain","count":15},{"language":"default","tag":"Web3 Apps","count":15}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[],"isAtlas":false,"googleFontsInlined":false},"customCss":[{"filePath":"styles.css","content":":root{--explain-card-bg:#f1f5f9;--explain-card-active-bg:#eef2ff;--explain-card-border:#c7d2fe}.dark{--explain-card-bg:#161b22;--explain-card-active-bg:#21262d;--explain-card-border:transparent}"},{"filePath":"custom.css","content":".home-code code{max-height:300px;overflow-y:auto}"}],"page":{"pagePath":"smart-contracts/anatomy/functions","slug":"/smart-contracts/anatomy/functions","pageMetadata":{"title":"Types and Interface","hide_table_of_contents":true,"description":"Learn how to define your contract's interface and use Rust and SDK types in its inputs, outputs, and state.","mode":"wide","href":"/smart-contracts/anatomy/functions"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Learn how to define your contract’s interface and use Rust and SDK types in its inputs, outputs, and state.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const File=({children})=>{return children};const __snippet_Block_5rg888=({children})=>{return children};const Block=__snippet_Block_5rg888;const ExplainCode=({children})=>{const _components={a:`a`,..._provideComponents()},{CodeBlock}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);const[activeBlock,setActiveBlock]=useState(0);const[code,setCode]=useState(null);const blockRefs=useRef({});const codeContainerRef=useRef(null);const ratioMap=useRef({});function toRaw(ref){const fullUrl=ref.slice(ref.indexOf(`https`));const[url]=fullUrl.split(`#`);const[org,repo,,branch,...pathSeg]=new URL(url).pathname.split(`/`).slice(1);return`https://raw.githubusercontent.com/${org}/${repo}/${branch}/${pathSeg.join(`/`)}`}async function fetchRaw(url,fromLine,toLine){let res;if(typeof window!==`undefined`){const validUntil=localStorage.getItem(`${url}-until`);if(validUntil\u0026\u0026Number(validUntil)>Date.now()){res=localStorage.getItem(url)}}if(!res){try{res=await(await fetch(url)).text();if(typeof window!==`undefined`){localStorage.setItem(url,res);localStorage.setItem(`${url}-until`,String(Date.now()+6e4))}}catch{return`Error fetching code, please try reloading`}}let lines=res.split(`\n`);const from=fromLine?Number(fromLine)-1:0;const to=toLine?Number(toLine):lines.length;lines=lines.slice(from,to);const indent=lines.reduce((prev,line)=>{if(!line.length)return prev;const m=line.match(/^\\s+/);return m?Math.min(prev,m[0].length):0},Infinity);return lines.map(l=>l.slice(indent===Infinity?0:indent)).join(`\n`)}function parseHighlights(str){const set=new Set;if(!str)return set;String(str).split(`,`).forEach(part=>{const[a,b]=part.trim().split(`-`);if(b){for(let i=Number(a);i\u003c=Number(b);i++)set.add(i)}else if(a)set.add(Number(a))});return set}const blocks=[];const files=[];function collect(node){if(!node)return;if(Array.isArray(node)){node.forEach(collect);return}if(typeof node!==`object`||!node.props)return;if(node.props.url!==undefined){files.push({...node.props})}else if(node.type===__snippet_Block_5rg888||node.props.fname!==undefined){blocks.push({text:node.props.children,highlight:node.props.highlights,fname:node.props.fname,type:node.props.type})}else{collect(node.props.children)}}collect(children);const activeFname=blocks[activeBlock]?.fname||files[0]?.fname;const fileKey=activeFname;const currentFile=files.find(f=>f.fname===activeFname)||files[0];useEffect(()=>{const observedEls=Object.entries(blockRefs.current).filter(([,el])=>el);const observer=new IntersectionObserver(entries=>{entries.forEach(entry=>{const idx=Number(entry.target.dataset.blockIdx);ratioMap.current[idx]=entry.intersectionRatio});let bestIdx=-1;let bestRatio=0;Object.entries(ratioMap.current).forEach(([idx,ratio])=>{if(ratio>bestRatio){bestRatio=ratio;bestIdx=Number(idx)}});if(bestIdx!==-1){setActiveBlock(bestIdx)}else{const zoneTop=window.innerHeight*.2;const allAboveZone=Object.entries(blockRefs.current).filter(([,el])=>el).every(([,el])=>el.getBoundingClientRect().bottom\u003czoneTop);if(allAboveZone)setActiveBlock(-1)}},{threshold:[0,.1,.25,.5,.75,1],rootMargin:`-20% 0px -50% 0px`});observedEls.forEach(([idx,el])=>{el.dataset.blockIdx=idx;observer.observe(el)});return()=>observer.disconnect()},[blocks.length]);useEffect(()=>{if(!currentFile?.url)return;setCode(null);const rawUrl=toRaw(currentFile.url);fetchRaw(rawUrl,currentFile.start,currentFile.end).then(setCode)},[fileKey]);const highlighted=parseHighlights(blocks[activeBlock]?.highlight);const firstHighlightedLine=highlighted.size>0?Math.min(...highlighted):null;useEffect(()=>{const container=codeContainerRef.current;if(!container||code===null||firstHighlightedLine===null)return;const frame=requestAnimationFrame(()=>{const highlightedLine=container.querySelector(`[data-line=\"${firstHighlightedLine}\"], [data-line-number=\"${firstHighlightedLine}\"], pre code > span:nth-child(${firstHighlightedLine})`);if(highlightedLine){const offset=highlightedLine.getBoundingClientRect().top-container.getBoundingClientRect().top;container.scrollTo({top:Math.max(0,container.scrollTop+offset-container.clientHeight/2+highlightedLine.clientHeight/2),behavior:`smooth`});return}const codeElement=container.querySelector(`pre code`);const lineHeight=codeElement?Number.parseFloat(getComputedStyle(codeElement).lineHeight):0;container.scrollTo({top:Math.max(0,(firstHighlightedLine-2)*(lineHeight||24)),behavior:`smooth`})});return()=>cancelAnimationFrame(frame)},[activeBlock,code,firstHighlightedLine]);return _jsx(`div`,{className:`mint-my-6 not-prose`,children:_jsxs(`div`,{className:`mint-flex mint-gap-8 mint-items-start`,children:[_jsx(`div`,{className:`mint-flex-[5] mint-flex mint-flex-col mint-gap-3 mint-min-w-0 mint-pb-[40vh]`,children:blocks.map((block,i)=>block.type?_jsx(`div`,{ref:el=>{blockRefs.current[i]=el},children:block.text},i):_jsx(`div`,{ref:el=>{blockRefs.current[i]=el},onClick:()=>setActiveBlock(i),className:[`mint-cursor-pointer mint-rounded-md mint-px-5 mint-py-4 mint-transition-all mint-duration-200 mint-border-l-4 mint-border-indigo-500`,activeBlock===i?`mint-shadow-sm`:`mint-opacity-60 hover:mint-opacity-90`].join(` `),style:{backgroundColor:activeBlock===i?`var(--explain-card-active-bg)`:`var(--explain-card-bg)`,border:activeBlock===i?`1px solid var(--explain-card-border)`:`1px solid transparent`},children:block.text},i))}),currentFile\u0026\u0026_jsxs(`div`,{className:`mint-flex-[6] mint-min-w-0 mint-sticky mint-top-6`,children:[_jsx(`div`,{ref:codeContainerRef,className:`mint-max-h-[calc(100vh-7rem)] mint-overflow-y-auto`,children:code===null?_jsx(`div`,{className:`mint-p-4 mint-text-xs mint-text-gray-500 dark:mint-text-gray-400`,children:`Loading...`}):_jsx(CodeBlock,{language:`rust`,filename:currentFile.fname,lines:true,highlight:JSON.stringify([...highlighted]),children:code},`${fileKey}-${activeBlock}`)}),_jsx(`div`,{className:`mint-mt-1 mint-flex mint-justify-end`,children:_jsx(_components.a,{href:`${currentFile.url}#L${currentFile.start}-L${currentFile.end}`,target:`_blank`,rel:`noreferrer noopener`,className:`mint-text-[0.6875rem] mint-font-medium mint-text-[#656d76] mint-no-underline hover:mint-text-[#1f2328] dark:mint-text-[#8b949e] dark:hover:mint-text-[#e6edf3]`,children:`See on GitHub`})})]})]})})};function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning,_MdxComponentBoundary}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Smart contracts expose functions so users can interact with them. There are different types of functions including `,_jsx(_components.code,{children:`read-only`}),`, `,_jsx(_components.code,{children:`private`}),` and `,_jsx(_components.code,{children:`payable`}),`.`]}),`\n`,_jsx(_MdxComponentBoundary,{name:`ExplainCode`,children:_jsx(ExplainCode,{children:_jsx(_MdxComponentBoundary,{name:`File`,children:_jsx(File,{fname:`auction`,url:`https://github.com/near-examples/auctions-tutorial/blob/main/contract-rs/01-basic-auction/src/lib.rs`,start:`2`,end:`84`})})})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`sdk-types`,children:`SDK types`}),`\n`,_jsx(_components.p,{children:`Smart contracts can receive, store, and return data using native Rust types such as strings, integers, booleans, maps, and vectors. The SDK also provides types for values that need special handling at the contract boundary.`}),`\n`,_jsx(Heading,{level:`3`,id:`large-integers`,children:`Large integers`}),`\n`,_jsxs(_components.p,{children:[`Contracts can store `,_jsx(_components.code,{children:`u64`}),` and `,_jsx(_components.code,{children:`u128`}),` values directly, but JSON consumers cannot always represent them without losing precision. Use the SDK’s `,_jsx(_components.code,{children:`U64`}),` and `,_jsx(_components.code,{children:`U128`}),` wrapper types for public inputs and outputs that need to be serialized as strings.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`JavaScript numbers cannot represent every integer above `,_jsx(_components.code,{children:`2^53 - 1`}),`. Keep native integer types in internal contract logic, and use the JSON wrapper types at the external interface when necessary.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`complex-objects`,children:`Complex objects`}),`\n`,_jsx(_components.p,{children:`Contracts can receive and return complex Rust structures. Objects used as JSON inputs or outputs need JSON serialization, while structures stored in contract state need Borsh serialization.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`rust`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`rust`,children:_jsxs(_components.code,{language:`rust`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`#[near(serializers `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` [json])]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`pub`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` struct`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` Bid`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` pub`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` bidder`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` AccountId`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` pub`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` amount`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` U128`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/smart-contracts/anatomy/serialization`,children:`serialization`}),` for the difference between interface and state serialization.`]}),`\n`,_jsx(Heading,{level:`3`,id:`tokens-and-accounts`,children:`Tokens and accounts`}),`\n`,_jsxs(_components.p,{children:[`Use `,_jsx(_components.code,{children:`NearToken`}),` to represent NEAR amounts. It provides constructors and accessors for yoctoNEAR, millinear, and NEAR values.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`rust`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light github-dark`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#24292e`,color:`#24292e`,\"--shiki-dark\":`#e1e4e8`},language:`rust`,children:_jsxs(_components.code,{language:`rust`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`let`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` deposit `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` NearToken`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`::`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`from_near`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`(`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`1`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`let`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` amount `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`=`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:` deposit`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`as_yoctonear`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`();`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The SDK’s `,_jsx(_components.code,{children:`AccountId`}),` type validates NEAR account IDs when values enter the contract. Prefer it to a plain `,_jsx(_components.code,{children:`String`}),` whenever a value represents an account.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{File,__snippet_Block_5rg888,Block,ExplainCode,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"github-dark"}},"config":{},"pageMetadata":{"title":"Types and Interface","hide_table_of_contents":true,"description":"Learn how to define your contract's interface and use Rust and SDK types in its inputs, outputs, and state.","mode":"wide","href":"/smart-contracts/anatomy/functions"}}},"mdxSourceWithNoJs":null,"noJsSplices":[[140,6361,")=>null;const __snippet_Block_5rg888=()=>null;const Block=undefined;const ExplainCode=()=>null;funct"]]},"mdxExtracts":{"tableOfContents":[{"title":"Contract’s Interface","slug":"contract’s-interface","depth":3,"children":[]},{"title":"Initialization Functions","slug":"initialization-functions","depth":3,"children":[]},{"title":"#[init]","slug":"#init","depth":4,"children":[]},{"title":"State Changing Functions","slug":"state-changing-functions","depth":3,"children":[]},{"title":"\u0026mut self","slug":"\u0026mut-self","depth":4,"children":[]},{"title":"Read-Only Functions","slug":"read-only-functions","depth":3,"children":[]},{"title":"\u0026self","slug":"\u0026self","depth":4,"children":[]},{"title":"Private Functions","slug":"private-functions","depth":3,"children":[]},{"title":"[#private]","slug":"#private","depth":4,"children":[]},{"title":"Payable Functions","slug":"payable-functions","depth":3,"children":[]},{"title":"[#payable]","slug":"#payable","depth":4,"children":[]},{"title":"Internal Functions","slug":"internal-functions","depth":3,"children":[]},{"title":"SDK types","slug":"sdk-types","depth":2,"children":[{"title":"Large integers","slug":"large-integers","depth":3,"children":[]},{"title":"Complex objects","slug":"complex-objects","depth":3,"children":[]},{"title":"Tokens and accounts","slug":"tokens-and-accounts","depth":3,"children":[]}]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/neardocs/86bd1b8645a68f87/gleap.js","/_mintlify/custom/neardocs/12aaa8206e84cdb3/scripts/patch-openapi.js"],"dynamicCss":".mint-sticky {\n position: sticky\n}\n.mint-top-6 {\n top: 1.5rem\n}\n.mint-my-6 {\n margin-top: 1.5rem;\n margin-bottom: 1.5rem\n}\n.mint-mt-1 {\n margin-top: 0.25rem\n}\n.mint-flex {\n display: flex\n}\n.mint-max-h-\\[calc\\(100vh-7rem\\)\\] {\n max-height: calc(100vh - 7rem)\n}\n.mint-min-w-0 {\n min-width: 0px\n}\n.mint-flex-\\[5\\] {\n flex: 5\n}\n.mint-flex-\\[6\\] {\n flex: 6\n}\n.mint-cursor-pointer {\n cursor: pointer\n}\n.mint-flex-col {\n flex-direction: column\n}\n.mint-items-start {\n align-items: flex-start\n}\n.mint-justify-end {\n justify-content: flex-end\n}\n.mint-gap-3 {\n gap: 0.75rem\n}\n.mint-gap-8 {\n gap: 2rem\n}\n.mint-overflow-y-auto {\n overflow-y: auto\n}\n.mint-rounded-md {\n border-radius: 0.375rem\n}\n.mint-border-l-4 {\n border-left-width: 4px\n}\n.mint-border-indigo-500 {\n --tw-border-opacity: 1;\n border-color: rgb(99 102 241 / var(--tw-border-opacity, 1))\n}\n.mint-p-4 {\n padding: 1rem\n}\n.mint-px-5 {\n padding-left: 1.25rem;\n padding-right: 1.25rem\n}\n.mint-py-4 {\n padding-top: 1rem;\n padding-bottom: 1rem\n}\n.mint-pb-\\[40vh\\] {\n padding-bottom: 40vh\n}\n.mint-text-\\[0\\.6875rem\\] {\n font-size: 0.6875rem\n}\n.mint-text-xs {\n font-size: 0.75rem;\n line-height: 1rem\n}\n.mint-font-medium {\n font-weight: 500\n}\n.mint-text-\\[\\#656d76\\] {\n --tw-text-opacity: 1;\n color: rgb(101 109 118 / var(--tw-text-opacity, 1))\n}\n.mint-text-gray-500 {\n --tw-text-opacity: 1;\n color: rgb(107 114 128 / var(--tw-text-opacity, 1))\n}\n.mint-no-underline {\n text-decoration-line: none\n}\n.mint-opacity-60 {\n opacity: 0.6\n}\n.mint-shadow-sm {\n --tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);\n --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);\n box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)\n}\n.mint-transition-all {\n transition-property: all;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 150ms\n}\n.mint-duration-200 {\n transition-duration: 200ms\n}\n.hover\\:mint-text-\\[\\#1f2328\\]:hover {\n --tw-text-opacity: 1;\n color: rgb(31 35 40 / var(--tw-text-opacity, 1))\n}\n.hover\\:mint-opacity-90:hover {\n opacity: 0.9\n}\n.dark\\:mint-text-\\[\\#8b949e\\]:is(.dark *) {\n --tw-text-opacity: 1;\n color: rgb(139 148 158 / var(--tw-text-opacity, 1))\n}\n.dark\\:mint-text-gray-400:is(.dark *) {\n --tw-text-opacity: 1;\n color: rgb(156 163 175 / var(--tw-text-opacity, 1))\n}\n.dark\\:hover\\:mint-text-\\[\\#e6edf3\\]:hover:is(.dark *) {\n --tw-text-opacity: 1;\n color: rgb(230 237 243 / var(--tw-text-opacity, 1))\n}","subdomain":"neardocs","siteName":"NEAR Docs","title":"Types and Interface - NEAR Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-22T15:21:02.363Z","originalFileLocation":"smart-contracts/anatomy/functions.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Learn how to define your contract\u0026#x27;s interface and use Rust and SDK types in its inputs, outputs, and state.\">\u003cmeta data-mint-head name=\"application-name\" content=\"NEAR Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Types and Interface - NEAR Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Learn how to define your contract\u0026#x27;s interface and use Rust and SDK types in its inputs, outputs, and state.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"NEAR Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.near.org/smart-contracts/anatomy/functions\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://neardocs.mintlify.app/_mintlify/api/og/v2?division=Anatomy+of+a+Contract\u0026amp;title=Types+and+Interface\u0026amp;description=Learn+how+to+define+your+contract%27s+interface+and+use+Rust+and+SDK+types+in+its+inputs%2C+outputs%2C+and+state.\u0026amp;theme=df941d03d19b89657352cf9a\u0026amp;signature=07903e09b1d4202ed9339e941fd4ec5faf1f1427f0f5439e6be31bece48226a2\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Types and Interface - NEAR Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Learn how to define your contract\u0026#x27;s interface and use Rust and SDK types in its inputs, outputs, and state.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://neardocs.mintlify.app/_mintlify/api/og/v2?division=Anatomy+of+a+Contract\u0026amp;title=Types+and+Interface\u0026amp;description=Learn+how+to+define+your+contract%27s+interface+and+use+Rust+and+SDK+types+in+its+inputs%2C+outputs%2C+and+state.\u0026amp;theme=df941d03d19b89657352cf9a\u0026amp;signature=07903e09b1d4202ed9339e941fd4ec5faf1f1427f0f5439e6be31bece48226a2\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/neardocs/jx3X3HW4FX2vbKtn/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"NEAR Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#1fb858\">\u003cmeta data-mint-head name=\"google-site-verification\" content=\"x36GvqeIYFjDAl2NNFM-83XykcMYMLRY6f9lgUZbDpA\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.near.org/smart-contracts/anatomy/functions\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/smart-contracts/anatomy/functions.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.near.org/#organization\",\"name\":\"NEAR Docs\",\"url\":\"https://docs.near.org\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/logo.svg?fit=max\u0026auto=format\u0026n=qO2GD-gji1aakHqN\u0026q=85\u0026s=fe9551b1c3085e39a97965b2886dad4a\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.near.org#website\",\"name\":\"NEAR Docs\",\"url\":\"https://docs.near.org\",\"publisher\":{\"@id\":\"https://docs.near.org/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.near.org/smart-contracts/anatomy/functions#webpage\",\"url\":\"https://docs.near.org/smart-contracts/anatomy/functions\",\"name\":\"Types and Interface\",\"description\":\"Learn how to define your contract's interface and use Rust and SDK types in its inputs, outputs, and state.\",\"dateModified\":\"2026-10-22T15:21:02.363Z\",\"isPartOf\":{\"@id\":\"https://docs.near.org#website\"},\"breadcrumb\":{\"@id\":\"https://docs.near.org/smart-contracts/anatomy/functions#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.near.org/smart-contracts/anatomy/functions#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Building Smart Contracts\",\"item\":\"https://docs.near.org/smart-contracts/anatomy/anatomy\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Anatomy of a Contract\",\"item\":\"https://docs.near.org/smart-contracts/anatomy/anatomy\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Types and Interface\",\"item\":\"https://docs.near.org/smart-contracts/anatomy/functions\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.near.org/smart-contracts/anatomy/functions#article\",\"headline\":\"Types and Interface\",\"name\":\"Types and Interface\",\"description\":\"Learn how to define your contract's interface and use Rust and SDK types in its inputs, outputs, and state.\",\"url\":\"https://docs.near.org/smart-contracts/anatomy/functions\",\"mainEntityOfPage\":{\"@id\":\"https://docs.near.org/smart-contracts/anatomy/functions#webpage\"},\"dateModified\":\"2026-10-22T15:21:02.363Z\",\"publisher\":{\"@id\":\"https://docs.near.org/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.near.org#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"NEAR Docs\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"NEAR Docs","nav":{"global":null,"tabs":[{"tab":"Home","icon":"house","pages":[{"title":"Home","href":""}]},{"tab":"Protocol","icon":"layers","pages":[{"title":"Protocol","href":"/protocol/network/architecture"}]},{"tab":"Smart Contracts","icon":"file-badge","groups":[{"group":" ","pages":[{"title":"What is a Smart Contract?","icon":"info","sidebarTitle":"Introduction","href":"/smart-contracts/what-is"},{"title":"Your First Smart Contract","icon":"rocket","sidebarTitle":"Quickstart","href":"/smart-contracts/quickstart"}]},{"group":"Building Smart Contracts","pages":[{"group":"Anatomy of a Contract","icon":"book-open","pages":[{"title":"Basic Anatomy","description":"Learn the basic anatomy of all smart contracts.","mode":"wide","href":"/smart-contracts/anatomy/anatomy"},{"title":"Types and Interface","mode":"wide","href":"/smart-contracts/anatomy/functions"},{"title":"State","sidebarTitle":"State (Storage)","description":"Explore how NEAR smart contracts manage their state.","mode":"wide","href":"/smart-contracts/anatomy/storage"},{"title":"Collections","href":"/smart-contracts/anatomy/collections"},{"title":"Environment","href":"/smart-contracts/anatomy/environment"},{"title":"Transfers \u0026 Actions","href":"/smart-contracts/anatomy/actions"},{"title":"Cross-Contract Calls","href":"/smart-contracts/anatomy/crosscontract"},{"title":"Contract Events","href":"/smart-contracts/anatomy/events"},{"title":"Yield and Resume","href":"/smart-contracts/anatomy/yield-resume"}]},{"group":"Testing","icon":"test-tube","pages":[{"title":"Unit Testing","href":"/smart-contracts/testing/unit-test"},{"title":"Integration Tests","href":"/smart-contracts/testing/integration-test"}]},{"group":"Deploy \u0026 Release","icon":"play","pages":[{"title":"Global Contracts","href":"/smart-contracts/global-contracts"},{"title":"Deploying","sidebarTitle":"Deploying and Using","href":"/smart-contracts/release/deploy"},{"title":"Updating Contracts","href":"/smart-contracts/release/upgrade"}]},{"group":"Security","icon":"shield","pages":[{"title":"Smart contract security checklist","sidebarTitle":"Security checklist","href":"/smart-contracts/security/checklist"},{"title":"Storage cost attacks","href":"/smart-contracts/security/storage"},{"group":"Cross-contract calls","pages":[{"title":"Private Callbacks","href":"/smart-contracts/security/cross-contract-calls/callbacks"},{"title":"Refund NEAR tokens","href":"/smart-contracts/security/cross-contract-calls/refunds"},{"title":"Do not panic in callbacks","href":"/smart-contracts/security/cross-contract-calls/callback-panics"},{"title":"Callbacks can fail","href":"/smart-contracts/security/cross-contract-calls/callback-failures"},{"title":"Fungible Token Implementation","href":"/smart-contracts/security/cross-contract-calls/ft-transfer-call"},{"title":"Balance Deduction","href":"/smart-contracts/security/cross-contract-calls/reentrancy"}]},{"title":"Require one yoctoNEAR","href":"/smart-contracts/security/one_yocto"},{"title":"Sybil attacks","href":"/smart-contracts/security/sybil"},{"title":"Front-running","href":"/smart-contracts/security/frontrunning"},{"title":"Duplicate token IDs","href":"/smart-contracts/security/duplicate-inputs"},{"title":"Random Numbers","href":"/smart-contracts/security/random"}]},{"group":"Advanced","icon":"zap","pages":[{"title":"Best Practices","href":"/smart-contracts/anatomy/best-practices"},{"title":"Serialization","href":"/smart-contracts/anatomy/serialization"},{"title":"Production Builds","sidebarTitle":"Production Builds","href":"/smart-contracts/anatomy/reduce-size"}]}]},{"group":"DevKit","pages":[{"title":"SDK Libraries","icon":"package","href":"/tools/sdk"},{"title":"Reference Contracts","icon":"list","href":"/tools/contracts-list"},{"title":"State Cleaner","icon":"trash-2","href":"/tools/clear-state"}]},{"group":"Tutorials","pages":[{"title":"Using our Basic Examples","icon":"book-open","href":"/smart-contracts/tutorials/basic-contracts"},{"group":"Cross Contracts","icon":"arrow-right-left","pages":[{"title":"Cross Contract Call","href":"/smart-contracts/tutorials/cross-contracts/xcc"}]},{"group":"Factories","icon":"layout-grid","pages":[{"title":"Factory","href":"/smart-contracts/tutorials/factories/factory"}]},{"title":"Token Drops","icon":"circle-dollar-sign","href":"/smart-contracts/tutorials/advanced/near-drop"},{"group":"Zero to Hero","icon":"rocket","pages":[{"title":"Fungible Tokens Zero to Hero","sidebarTitle":"Build a FT Contract from Scratch","href":"/smart-contracts/tutorials/zero-to-hero/fts"},{"title":"NFT Zero to Hero","sidebarTitle":"Build a NFT Contract from Scratch","href":"/smart-contracts/tutorials/zero-to-hero/nfts"}]}]}]},{"tab":"Web3 Apps","icon":"terminal","pages":[{"title":"Web3 Apps","href":"/web3-apps/what-is"}]},{"tab":"Multi-Chain","icon":"link-2","pages":[{"title":"Multi-Chain","href":"/chain-abstraction/what-is"}]},{"tab":"Tokens \u0026 Primitives","icon":"coins","pages":[{"title":"Tokens \u0026 Primitives","href":"/primitives/what-is"}]},{"tab":"Data Infra","icon":"database","pages":[{"title":"Data Infra","href":"/data-infrastructure/what-is"}]},{"tab":"Integrations","icon":"plug","pages":[{"title":"Integrations","href":"/integrations/exchange-integration"}]},{"tab":"RPC","icon":"server","pages":[{"title":"RPC","href":"/api/rpc/introduction"}]}]},"title":"Types and Interface - NEAR Docs","buildId":"dpl_2oYXwqkEXirXBPk8wV1FtM5USFWi","deploymentId":"dpl_2oYXwqkEXirXBPk8wV1FtM5USFWi","dynamics":[],"chunks":[]}