In NEAR Protocol, verifying that a transaction actually comes from the user (not from a website with a Function Call key) is critical for security, especially when transferring valuable assets. Requiring 1 yoctoNEAR (the smallest unit of NEAR) is a simple and effective way to ensure user authorization.Documentation Index
Fetch the complete documentation index at: https://docs.near.org/llms.txt
Use this file to discover all available pages before exploring further.
NEAR Access Key System
NEAR uses an access key system to simplify account management. There are two main types of keys:1. Full Access Keys
- Full control over an account
- Can perform all actions (transfers, deployments, etc.)
- Can attach NEAR as deposit
- Stored only in user’s wallet - never shared with websites.
2. Function Call Keys
- Limited permissions - can only call specified smart contract methods
- Cannot attach NEAR as deposit
- Created when users sign in to websites
- Stored in the website - website can use them automatically.
The Security Problem
How Website Sign-In Works
When a user signs in to a website to interact with your contract:- A
Function Callkey is created - The key is stored in the website (browser storage)
- The website can use this key to call authorized methods automatically
- No user interaction required for each transaction.
The Risk
For most operations, this is convenient and secure. However, for valuable asset transfers (NFTs, Fungible Tokens, large amounts of NEAR), this creates a security risk:- Website has the key - can initiate transfers without user confirmation
- No user awareness - user might not know a transfer is happening
- Malicious websites - compromised or malicious sites could drain assets
- User can’t verify - no way to ensure the user actually authorized the transfer.
- Transferring NFTs
- Transferring Fungible Tokens (FTs)
- Large NEAR transfers
- Any operation involving valuable assets
Solution: Require 1 YoctoNEAR
How It Works
Require users to attach 1 yoctoNEAR (1 yⓃ) to sensitive operations:Why This Works
- Function Call keys cannot attach NEAR - they can only call methods without deposits
- Only Full Access keys can attach NEAR - these are stored in the user’s wallet
- Wallet requires user confirmation - when NEAR is attached, wallet prompts user
- User must approve - transaction cannot proceed without explicit user approval.
Implementation Example
NFT Transfer with Verification
Fungible Token Transfer
When to Use This Pattern
Use 1 YoctoNEAR Requirement For:
- ✅ NFT transfers
- ✅ Fungible Token transfers
- ✅ Large NEAR transfers
- ✅ Account ownership changes
- ✅ Permission modifications
- ✅ Any operation involving valuable assets
Not Necessary For:
- ❌ Read-only operations (view methods)
- ❌ Low-value operations
- ❌ Operations that don’t transfer assets
- ❌ Public data queries
Best Practices
- Always require 1 yoctoNEAR for asset transfers
- Document the requirement - tell users why it’s needed
- Return the yoctoNEAR if you don’t need it (optional, but user-friendly)
- Use consistent pattern - apply to all sensitive operations
- Test with Function Call keys - ensure they fail without deposit