Know which account called you, how much gas and tokens were attached, and more.
The environment is a set of variables and functions that are available to your smart contract when it is executed. It provides information such as who called the method, how much money was attached to the call, and how many computational resources are available.Every method execution has an environment associated with information such as:
Who called the method
How much money is attached to the call
How many computational resources are available
The current timestamp
Helper functions for Public Key derivation, for example
The current_account contains the address in which your contract is deployed. This is very useful to implement ownership, e.g. making a public method only callable by the contract itself.
The predecessor is the account that called the method in the contract. Meanwhile, the signer is the account that signed the initial transaction.During a simple transaction (no cross-contract calls) the predecessor is the same as the signer. For example, if alice.near calls contract.near, from the contract’s perspective, alice.near is both the signer and the predecessor. However, if contract.near creates a cross-contract call, then the predecessor changes down the line. In the example below, when pool.near executes, it would see contract.near as the predecessor and alice.near as the signer.You can access information about the users interacting with your smart contract
In most scenarios you will only need to know the predecessor. However, there are situations in which the signer is very useful. For example, when adding NFTs into this marketplace, the contract checks that the signer, i.e. the person who generated the transaction chain, is the NFT owner.
signer_account_pk returns the signer’s public key as a near-sdk-rs PublicKey — not a preformatted <scheme>:<base58> string. If the transaction was signed with a post-quantum ml-dsa-65 key, that public key is much larger — 1952 bytes, versus 32 for ed25519 — so keep that in mind if your contract stores, compares, or serializes signer public keys.
attached_deposit represents the amount of yoctoNEAR the predecessor attached to the call.This amount is already deposited in your contract’s account, and is automatically returned to the predecessor if your method panics.
If you make a cross-contract call and it panics, the funds are sent back to your contract. See how to handle this situation in the callback section
account_balance represents the balance of your contract (current_account).It includes the attached_deposit, since it was deposited when the method execution started.If the contract has any locked $NEAR, it will appear in account_locked_balance.
The timestamp attribute represents the approximated UNIX timestamp in nanoseconds at which this call was executed. It quantifies time passing in a human way, enabling us to check if a specific date has passed or not.
The NEAR blockchain groups blocks in Epochs. The current_epoch attribute measures how many epochs have passed so far. It is very useful to coordinate with other contracts that measure time in epochs, such as the validators.
Your contract has a limited number of computational resources to use on each call. Such resources are measured in Gas.Gas can be thought of as wall time, where 1 PetaGas (1_000 TGas) is ~1 second of compute time.Each code instruction costs a certain amount of Gas, and if you run out of it, the execution halts with the error message Exceeded the prepaid gas.The environment gives you access to two gas-related arguments: prepaid_gas and used_gas.
Recovers an ECDSA signer address from a 32-byte message hash and a corresponding signature along with v recovery byte. Takes in an additional flag to check for malleability of the signature which is generally only ideal for transactions. Returns 64 bytes representing the public key if the recovery was successful.
Panic String
env::panic_str(message)
Terminates the execution of the program with the UTF-8 encoded message.
Log String
env::log_str(message)
Logs the string message. This message is stored on chain.
Validator Stake
env::validator_stake(account_id)
For a given account return its current stake. If the account is not a validator, returns 0.
Validator Total Stake
env::validator_total_stake()
Returns the total stake of validators in the current epoch.
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":"6ad74973bb70dd358f80dea9","collectionId":"26a84b54-b5a5-4b7c-8e56-d6facc9f0d1f","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ad74973bb70dd358f80dea9"},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6ad74973bb70dd358f80dea9","clientVersion":"0.0.3926","searchFilterCounts":[{"language":"default","tag":"RPC","count":47},{"language":"default","tag":"Smart Contracts","count":44},{"language":"default","tag":"Building Smart Contracts","count":30},{"language":"default","tag":"Protocol","count":23},{"language":"default","tag":"Tokens \u0026 Primitives","count":22},{"language":"default","tag":"Home","count":17},{"language":"default","tag":"Concepts","count":17},{"language":"default","tag":"Tutorials","count":16},{"language":"default","tag":"Multi-Chain","count":15},{"language":"default","tag":"Web3 Apps","count":15}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"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/environment","slug":"/smart-contracts/anatomy/environment","pageMetadata":{"title":"Environment","description":"Know which account called you, how much gas and tokens were attached, and more.","href":"/smart-contracts/anatomy/environment"},"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: \"Know which account called you, how much gas and tokens were attached, and more.\"\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];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,hr:`hr`,img:`img`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,Table,Tip,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`The environment is a set of variables and functions that are available to your smart contract when it is executed. It provides information such as who called the method, how much money was attached to the call, and how many computational resources are available.`}),`\n`,_jsx(_components.p,{children:`Every method execution has an environment associated with information such as:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Who called the method`}),`\n`,_jsx(_components.li,{children:`How much money is attached to the call`}),`\n`,_jsx(_components.li,{children:`How many computational resources are available`}),`\n`,_jsx(_components.li,{children:`The current timestamp`}),`\n`,_jsx(_components.li,{children:`Helper functions for Public Key derivation, for example`}),`\n`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`environment-variables`,children:`Environment Variables`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Variable Name`}),_jsx(_components.th,{children:`SDK Variable`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Predecessor`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::predecessor_account_id()`})}),_jsx(_components.td,{children:`Account ID that called this method`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Current Account`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::current_account_id()`})}),_jsx(_components.td,{children:`Account ID of this smart contract`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Signer`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::signer_account_id()`})}),_jsx(_components.td,{children:`Account ID that signed the transaction leading to this execution`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Attached Deposit`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::attached_deposit()`})}),_jsx(_components.td,{children:`Amount in yoctoNEAR attached to the call by the predecessor`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Account Balance`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::account_balance()`})}),_jsx(_components.td,{children:`Balance of this smart contract (including Attached Deposit)`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Prepaid Gas`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::prepaid_gas()`})}),_jsx(_components.td,{children:`Amount of gas available for execution`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Timestamp`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::block_timestamp()`})}),_jsx(_components.td,{children:`Current timestamp (number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC)`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Current Epoch`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::epoch_height()`})}),_jsx(_components.td,{children:`Current epoch in the blockchain`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Block Index`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::block_index()`})}),_jsx(_components.td,{children:`Current block index (a.k.a. block height)`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Storage Used`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::storage_usage()`})}),_jsx(_components.td,{children:`Current storage used by this smart contract in bytes`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Storage Byte Cost`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::storage_byte_cost()`})}),_jsx(_components.td,{children:`Current storage cost per byte in yoctoNEAR`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Used Gas`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::used_gas()`})}),_jsx(_components.td,{children:`Amount of gas used for execution`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Signer Public Key`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::signer_account_pk()`})}),_jsx(_components.td,{children:`Sender Public Key`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Account Locked Balance`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::account_locked_balance()`})}),_jsx(_components.td,{children:`Balance of this smart contract that is locked`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`who-is-calling-who-am-i`,children:`Who is Calling? Who am I?`}),`\n`,_jsxs(_components.p,{children:[`The environment gives you access to 3 important users: the `,_jsx(_components.code,{children:`current_account`}),`, the `,_jsx(_components.code,{children:`predecessor`}),`, and the `,_jsx(_components.code,{children:`signer`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`current-account`,children:`Current Account`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`current_account`}),` contains the address in which your contract is deployed. This is very useful to implement ownership, e.g. making a public method only callable by the contract itself.`]}),`\n`,_jsx(Heading,{level:`3`,id:`predecessor-and-signer`,children:`Predecessor and Signer`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`predecessor`}),` is the account that called the method in the contract. Meanwhile, the `,_jsx(_components.code,{children:`signer`}),` is the account that `,_jsx(_components.em,{children:`signed`}),` the initial transaction.`]}),`\n`,_jsxs(_components.p,{children:[`During a simple transaction (no `,_jsx(_components.a,{href:`/smart-contracts/anatomy/crosscontract`,children:`cross-contract calls`}),`) the `,_jsx(_components.code,{children:`predecessor`}),` is the same as the `,_jsx(_components.code,{children:`signer`}),`. For example, if `,_jsx(_components.strong,{children:`alice.near`}),` calls `,_jsx(_components.strong,{children:`contract.near`}),`, from the contract’s perspective, `,_jsx(_components.strong,{children:`alice.near`}),` is both the `,_jsx(_components.code,{children:`signer`}),` and the `,_jsx(_components.code,{children:`predecessor`}),`. However, if `,_jsx(_components.strong,{children:`contract.near`}),` creates a `,_jsx(_components.a,{href:`/smart-contracts/anatomy/crosscontract`,children:`cross-contract call`}),`, then the `,_jsx(_components.code,{children:`predecessor`}),` changes down the line. In the example below, when `,_jsx(_components.strong,{children:`pool.near`}),` executes, it would see `,_jsx(_components.strong,{children:`contract.near`}),` as the `,_jsx(_components.code,{children:`predecessor`}),` and `,_jsx(_components.strong,{children:`alice.near`}),` as the `,_jsx(_components.code,{children:`signer`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.img,{src:`https://miro.medium.com/max/1400/1*LquSNOoRyXpITQF9ugsDpQ.png`,alt:`img`}),`\n`,_jsx(_components.em,{children:`You can access information about the users interacting with your smart contract`})]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`In most scenarios you will `,_jsx(_components.strong,{children:`only need to know the predecessor`}),`. However, there are situations in which the signer is very useful. For example, when adding `,_jsx(_components.a,{href:`/primitives/nft/nft`,children:`NFTs`}),` into `,_jsx(_components.a,{href:`https://github.com/near-examples/nft-tutorial/blob/7fb267b83899d1f65f1bceb71804430fab62c7a7/market-contract/src/nft_callbacks.rs#L42`,children:`this marketplace`}),`, the contract checks that the `,_jsx(_components.code,{children:`signer`}),`, i.e. the person who generated the transaction chain, is the NFT owner.`]})}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`signer_account_pk`}),` returns the signer’s public key as a near-sdk-rs `,_jsx(_components.code,{children:`PublicKey`}),` — not a preformatted `,_jsx(_components.code,{children:`\u003cscheme>:\u003cbase58>`}),` string. If the transaction was signed with a post-quantum `,_jsx(_components.a,{href:`/protocol/accounts-contracts/access-keys#signature-schemes`,children:_jsx(_components.code,{children:`ml-dsa-65`})}),` key, that public key is much larger — 1952 bytes, versus 32 for `,_jsx(_components.code,{children:`ed25519`}),` — so keep that in mind if your contract stores, compares, or serializes signer public keys.`]})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`balances-and-attached-near`,children:`Balances and Attached NEAR`}),`\n`,_jsxs(_components.p,{children:[`The environment gives you access to 3 token-related parameters, all expressed in yoctoNEAR (1 Ⓝ = 10`,_jsx(`sup`,{children:`24`}),`yⓃ):`]}),`\n`,_jsx(Heading,{level:`3`,id:`attached-deposit`,children:`Attached Deposit`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`attached_deposit`}),` represents the amount of yoctoNEAR the predecessor attached to the call.`]}),`\n`,_jsxs(_components.p,{children:[`This amount is `,_jsx(_components.strong,{children:`already deposited`}),` in your contract’s account, and is `,_jsx(_components.strong,{children:`automatically returned`}),` to the `,_jsx(_components.code,{children:`predecessor`}),` if your `,_jsx(_components.strong,{children:`method panics`}),`.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If you make a `,_jsx(_components.a,{href:`/smart-contracts/anatomy/crosscontract`,children:`cross-contract call`}),` and it panics, the funds are sent back to `,_jsx(_components.strong,{children:`your contract`}),`. See how to handle this situation in the `,_jsx(_components.a,{href:`/smart-contracts/anatomy/crosscontract#what-happens-if-the-function-i-call-fails`,children:`callback section`})]})}),`\n`,_jsx(Heading,{level:`3`,id:`account-balance`,children:`Account Balance`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`account_balance`}),` represents the balance of your contract (`,_jsx(_components.code,{children:`current_account`}),`).`]}),`\n`,_jsxs(_components.p,{children:[`It includes the `,_jsx(_components.code,{children:`attached_deposit`}),`, since it was deposited when the method execution started.`]}),`\n`,_jsxs(_components.p,{children:[`If the contract has any locked `,_jsx(_components.code,{children:`$NEAR`}),`, it will appear in `,_jsx(_components.code,{children:`account_locked_balance`}),`.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`3`,id:`storage-used`,children:`Storage Used`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`storage_used`}),` represents the amount of `,_jsx(_components.a,{href:`/smart-contracts/anatomy/storage`,children:`storage`}),` that is currently being used by your contract.`]}),`\n`,_jsx(Tip,{children:_jsx(_components.p,{children:`If you want to know how much storage a structure uses, print the storage before and after storing it.`})}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`telling-the-time`,children:`Telling the Time`}),`\n`,_jsx(_components.p,{children:`The environment exposes three different ways to tell the pass of time, each representing a different dimension of the underlying blockchain.`}),`\n`,_jsx(Heading,{level:`3`,id:`timestamp`,children:`Timestamp`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`timestamp`}),` attribute represents the approximated `,_jsx(_components.strong,{children:`UNIX timestamp`}),` in `,_jsx(_components.strong,{children:`nanoseconds`}),` at which this call was executed. It quantifies time passing in a human way, enabling us to check if a specific date has passed or not.`]}),`\n`,_jsx(Heading,{level:`3`,id:`current-epoch`,children:`Current Epoch`}),`\n`,_jsxs(_components.p,{children:[`The NEAR blockchain groups blocks in `,_jsx(_components.a,{href:`/protocol/network/epoch`,children:`Epochs`}),`. The `,_jsx(_components.code,{children:`current_epoch`}),` attribute measures how many epochs have passed so far. It is very useful to coordinate with other contracts that measure time in epochs, such as the `,_jsx(_components.a,{href:`/protocol/network/validators`,children:`validators`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`block-index`,children:`Block Index`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`block_index`}),` represents the index of the block in which this transaction will be added to the blockchain.`]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`gas`,children:`Gas`}),`\n`,_jsxs(_components.p,{children:[`Your contract has a `,_jsx(_components.strong,{children:`limited number of computational resources`}),` to use on each call. Such resources are measured in `,_jsx(_components.a,{href:`/protocol/transactions/gas`,children:`Gas`}),`.`]}),`\n`,_jsx(_components.p,{children:`Gas can be thought of as wall time, where 1 PetaGas (1_000 TGas) is ~1 second of compute time.`}),`\n`,_jsxs(_components.p,{children:[`Each code instruction costs a certain amount of Gas, and if you run out of it, the execution halts with the error message `,_jsx(_components.code,{children:`Exceeded the prepaid gas`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`The environment gives you access to two gas-related arguments: `,_jsx(_components.code,{children:`prepaid_gas`}),` and `,_jsx(_components.code,{children:`used_gas`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`prepaid-gas`,children:`Prepaid Gas`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`prepaid_gas`}),` represents the amount of Gas the `,_jsx(_components.code,{children:`predecessor`}),` attached to this call. It cannot exceed the limit 300TGas (300 * 10`,_jsx(`sup`,{children:`12`}),` Gas).`]}),`\n`,_jsx(Heading,{level:`3`,id:`used-gas`,children:`Used Gas`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`used_gas`}),` contains the amount of Gas that has been used so far. It is useful to estimate the Gas cost of running a method.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`During `,_jsx(_components.a,{href:`/smart-contracts/anatomy/crosscontract`,children:`cross-contract calls`}),` give the callback enough Gas for its worst case, not its average. See `,_jsx(_components.a,{href:`/smart-contracts/security/cross-contract-calls/callback-failures`,children:`callbacks can fail`}),`.`]})}),`\n`,_jsxs(Tip,{children:[_jsxs(_components.p,{children:[`If you already `,_jsx(_components.a,{href:`/protocol/transactions/gas#estimating-costs-for-a-call`,children:`estimated the Gas`}),` a method needs, you can ensure it never runs out of Gas by using `,_jsx(_components.code,{children:`assert`})]}),_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:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` REQUIRED_GAS`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`:`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` Gas`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:` =`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:` Gas`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`(`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:`20_000_000_000_000`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`); `}),_jsx(_components.span,{style:{color:`#6A737D`,\"--shiki-dark\":`#6A737D`},children:`// 20 TGas`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`assert!`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`(`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`env`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`::`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#B392F0`},children:`prepaid_gas`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`() `}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#F97583`},children:`>=`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#79B8FF`},children:` REQUIRED_GAS`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`, `}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#9ECBFF`},children:`\"Please attach at least 20 TGas\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#E1E4E8`},children:`);`})]}),`\n`]})})})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`environment-functions`,children:`Environment Functions`}),`\n`,_jsx(_components.p,{children:`Besides environmental variables, the SDK also exposes some functions to perform basic cryptographic operations`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Function Name`}),_jsx(_components.th,{children:`SDK method`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`SHA 256`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::sha256(value)`})}),_jsx(_components.td,{children:`Hashes a sequence of bytes using sha256.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Keccak 256`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::keccak256(value)`})}),_jsx(_components.td,{children:`Hashes a sequence of bytes using keccak256.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Keccak 512`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::keccak512(value)`})}),_jsx(_components.td,{children:`Hashes a sequence of bytes using keccak512.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`SHA 256 (Array)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::sha256_array(value)`})}),_jsx(_components.td,{children:`Hashes the bytes using the SHA-256 hash function. This returns a 32 byte hash.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Keccak 256 (Array)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::keccak256_array(value)`})}),_jsx(_components.td,{children:`Hashes the bytes using the Keccak-256 hash function. This returns a 32 byte hash.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Keccak 512 (Array)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::keccak512_array(value)`})}),_jsx(_components.td,{children:`Hashes the bytes using the Keccak-512 hash function. This returns a 64 byte hash.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`RIPEMD 160 (Array)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::ripemd160_array(value)`})}),_jsx(_components.td,{children:`Hashes the bytes using the RIPEMD-160 hash function. This returns a 20 byte hash.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`EC Recover`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::ecrecover(hash, signature, v, malleability_flag)`})}),_jsxs(_components.td,{children:[`Recovers an ECDSA signer address from a 32-byte message `,_jsx(_components.code,{children:`hash`}),` and a corresponding `,_jsx(_components.code,{children:`signature`}),` along with `,_jsx(_components.code,{children:`v`}),` recovery byte. Takes in an additional flag to check for malleability of the signature which is generally only ideal for transactions. Returns 64 bytes representing the public key if the recovery was successful.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Panic String`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::panic_str(message)`})}),_jsx(_components.td,{children:`Terminates the execution of the program with the UTF-8 encoded message.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Log String`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::log_str(message)`})}),_jsx(_components.td,{children:`Logs the string message. This message is stored on chain.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Validator Stake`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::validator_stake(account_id)`})}),_jsx(_components.td,{children:`For a given account return its current stake. If the account is not a validator, returns 0.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Validator Total Stake`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`env::validator_total_stake()`})}),_jsx(_components.td,{children:`Returns the total stake of validators in the current epoch.`})]})]})]}),`\n`,_jsx(_components.hr,{})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{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":"Environment","description":"Know which account called you, how much gas and tokens were attached, and more.","href":"/smart-contracts/anatomy/environment"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Environment Variables","slug":"environment-variables","depth":2,"children":[]},{"title":"Who is Calling? Who am I?","slug":"who-is-calling-who-am-i","depth":2,"children":[{"title":"Current Account","slug":"current-account","depth":3,"children":[]},{"title":"Predecessor and Signer","slug":"predecessor-and-signer","depth":3,"children":[]}]},{"title":"Balances and Attached NEAR","slug":"balances-and-attached-near","depth":2,"children":[{"title":"Attached Deposit","slug":"attached-deposit","depth":3,"children":[]},{"title":"Account Balance","slug":"account-balance","depth":3,"children":[]},{"title":"Storage Used","slug":"storage-used","depth":3,"children":[]}]},{"title":"Telling the Time","slug":"telling-the-time","depth":2,"children":[{"title":"Timestamp","slug":"timestamp","depth":3,"children":[]},{"title":"Current Epoch","slug":"current-epoch","depth":3,"children":[]},{"title":"Block Index","slug":"block-index","depth":3,"children":[]}]},{"title":"Gas","slug":"gas","depth":2,"children":[{"title":"Prepaid Gas","slug":"prepaid-gas","depth":3,"children":[]},{"title":"Used Gas","slug":"used-gas","depth":3,"children":[]}]},{"title":"Environment Functions","slug":"environment-functions","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/neardocs/86bd1b8645a68f87/gleap.js","/_mintlify/custom/neardocs/12aaa8206e84cdb3/scripts/patch-openapi.js"],"subdomain":"neardocs","siteName":"NEAR Docs","title":"Environment - NEAR Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-20T09:06:11.762Z","originalFileLocation":"smart-contracts/anatomy/environment.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=\"Know which account called you, how much gas and tokens were attached, and more.\">\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=\"Environment - NEAR Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Know which account called you, how much gas and tokens were attached, and more.\">\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/environment\">\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=Environment\u0026amp;description=Know+which+account+called+you%2C+how+much+gas+and+tokens+were+attached%2C+and+more.\u0026amp;theme=ad26cc3b2babbfd6de8c3753\u0026amp;signature=1067039a25dbaf31aef6c1322bf28dd4636deff4af531b67e83ce7f200fff5e9\">\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=\"Environment - NEAR Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Know which account called you, how much gas and tokens were attached, and more.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://neardocs.mintlify.app/_mintlify/api/og/v2?division=Anatomy+of+a+Contract\u0026amp;title=Environment\u0026amp;description=Know+which+account+called+you%2C+how+much+gas+and+tokens+were+attached%2C+and+more.\u0026amp;theme=ad26cc3b2babbfd6de8c3753\u0026amp;signature=1067039a25dbaf31aef6c1322bf28dd4636deff4af531b67e83ce7f200fff5e9\">\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/environment\">\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/environment.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/environment#webpage\",\"url\":\"https://docs.near.org/smart-contracts/anatomy/environment\",\"name\":\"Environment\",\"description\":\"Know which account called you, how much gas and tokens were attached, and more.\",\"dateModified\":\"2026-10-20T09:06:11.762Z\",\"isPartOf\":{\"@id\":\"https://docs.near.org#website\"},\"breadcrumb\":{\"@id\":\"https://docs.near.org/smart-contracts/anatomy/environment#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.near.org/smart-contracts/anatomy/environment#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\":\"Environment\",\"item\":\"https://docs.near.org/smart-contracts/anatomy/environment\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.near.org/smart-contracts/anatomy/environment#article\",\"headline\":\"Environment\",\"name\":\"Environment\",\"description\":\"Know which account called you, how much gas and tokens were attached, and more.\",\"url\":\"https://docs.near.org/smart-contracts/anatomy/environment\",\"mainEntityOfPage\":{\"@id\":\"https://docs.near.org/smart-contracts/anatomy/environment#webpage\"},\"dateModified\":\"2026-10-20T09:06:11.762Z\",\"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","mode":"wide","href":"/smart-contracts/anatomy/anatomy"},{"title":"Types and Interface","mode":"wide","href":"/smart-contracts/anatomy/functions"},{"title":"State","sidebarTitle":"State (Storage)","mode":"wide","href":"/smart-contracts/anatomy/storage"},{"title":"Collections","description":"Efficiently store, access, and manage data in smart contracts.","href":"/smart-contracts/anatomy/collections"},{"title":"Environment","href":"/smart-contracts/anatomy/environment"},{"title":"Transfers \u0026 Actions","description":"Learn how contracts can make transfers, call other contracts, and more","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":"Environment - NEAR Docs","buildId":"dpl_9DauxEjb9gzCtcuhPQFbquJvx7FJ","deploymentId":"dpl_9DauxEjb9gzCtcuhPQFbquJvx7FJ","dynamics":["a74be98ba7"],"chunks":["zoom-image-lightbox-D4WcYaf4.js","PlusIcon-CwhPVjTe.js","lightbox-handle-r17bVUz3.js"]}