
New to Smart Contract Development?
New to Smart Contract Development?
Do not worry if you don’t know how smart contract blockchains work. As a developer, it is sufficient to understand that NEAR smart contracts:
- Have limited computational resources.
- Interact with other contracts in an asynchronous way.
- Deal with real money, for which security must be a top concern.
Where do contracts live?
Smart contracts are deployed to NEAR accounts. Any NEAR account can hold a contract and must pay for the contract’s code and the data it stores. Once in an account, anyone can interact with the contract. Thanks to the underlying network structure, executing code from a contract is both fast (average finality of 1.2 seconds) and cheap. Read-only operations are free for everyone.Storing 100 KB costs 1 Ⓝ, so deploying a contract generally costs only a few
$NEARs.What can they do?
Smart contracts have complete control over the account and can therefore perform any action on its behalf. For example, contracts can:- Transfer
$NEARtokens - Call methods on other contracts
- Create new accounts and deploy contracts on them
- Update their own code
What contracts cannot do
- Smart contracts cannot access the internet, so they cannot make HTTP requests or access external data
- Smart contracts cannot execute automatically; they must be called by an external account
A contract is not a backend
Contract state is for the data the contract needs to enforce its rules, such as balances, ownership, or the current highest bid. It is not a database for your app. Everything a transaction does is already recorded on-chain: who called which method, the arguments they passed, and the tokens they attached. Indexers and data services can read this activity back at any time. If your app only needs to display some data, such as messages, posts or history, have the contract validate the call and leave the data in the transaction, then read it with an indexer instead of storing it in the contract. Storage is also the expensive part: every byte requires staking NEAR (1 Ⓝ per 100 KB), while computation only costs gas. Never store values you can derive from other values. For example, if a message is premium when the user attaches at least 0.1 Ⓝ, store the amount or the premium flag, not both.Example: a guest book
Example: a guest book
A guest book that stores every message in the contract pays for the storage of each message for as long as it exists. Instead, a production guest book can expose an
add_message(text) method that only checks the attached deposit. The message stays in the transaction’s arguments, and the frontend lists messages by asking an indexer for every call to add_message.What are they used for?
Smart contracts are used to create decentralized applications. Common examples include:- Decentralized Autonomous Organizations, where users create and vote on proposals
- Marketplaces, where users create and trade digital artworks
- Decentralized exchanges, where users can trade different currencies
- And many more…
$NEAR. If the goal is met in time, the creator can claim the funds. Otherwise, the backers are refunded.