Into_NEAR_2: Access Keys
author: cenwadike.near || twitter: https://twitter.com/iam_combi16
In popular blockchains like Bitcoin and Ethereum, an account usually refers to a public key or its derivative. As such, using an account actually refers to using the private key of an account to sign transactions.
NEAR accounts have the unique feature of holding multiple public/private key pairs, called Access Keys. Each Access Key has its own set of permissions that grants limited access over an account.
Access keys are similar to OAuths, enabling a user to grant limited access over their account to third parties.
Benefits of Access Keys
Because the concept of Access Keys is unique to NEAR Protocol, it is worth first understanding why and how they can be used.
Application Safety
Creating an access key for specific NEAR contracts, allows a user to call specific methods in a specified contract.
A user can safely give the key to the smart contract without the need to interrupt the user experience to sign each transaction.
Access Key also removes the overhead for implementing crude “allowance” by NEAR application developers, reducing smart contract attack surface.
Replacing Keys
Just as how users would change their password, Access Keys can easily be swapped or removed.
This can be really useful when an Access Key or smart contract previously given an access key becomes compromised.
Implementing Key Recovery
A user could create a key-recovery contract in their account with a corresponding “recovery” access key for a trusted entity (say a friend). Such a key could only be used to start the recovery of the account.
When needed the trusted entity could trigger the recovery process, helping the user create a new master key.
Key Types
NEAR implements two types of keys:
- Full Access keys
- Function Call keys
Full Access Keys
Full Access keys have full control of an account, similar to having administrator privileges on your operating system.
Particularly, Full Access keys can be used to sign any transaction on an account’s behalf. These transactions could:
- Create immediate sub-accounts
- Delete the accounts (but not sub-accounts)
- Add or remove Access Keys
- Deploy contract in the account
- Call methods on any contract
- Transfer NEARⓃ
Having Full Access Key to an account, equals total control over the account.
It is also important to note that the first Full Access Key is created when an account is created.
Function Call Keys
Function Call Keys only have permission to call non-payable methods on contracts, ie. methods that do not require user to attach NEARⓃ.
Function Call Keys are defined by three attributes:
- receiver_id: The contract which the key allows to call. No other contract can be called using this key.
- method_names: The contract’s methods the key allows to call (Optional). If omitted, all contract methods may be called.
- allowance: The amount of Ⓝ allowed to spend on gas (Optional). If omitted, the key will only be allowed to call view (read-only) methods.
Function Call Keys main purpose is to be handed to contracts, so that contracts can make calls on behalf of an account.
NEAR simplifies creating and giving Function Call Keys to dApps by implementing a sign-in process. dApps can ask users to sign-in using a wallet, which automatically creates and gives a Function Call Key to the dApp.
With the Function Call Key, a dApp will be able to call specific methods on an account’s behalf, with a default allowance of 0.25Ⓝ for gas.
If a dApp requests to transfer any amount of tokens with the Function Call Key, the user will be prompted once more by the wallet to authorize the transaction.
Locked Accounts
If all keys from an account are removed, the account becomes locked. This means that no external actor can perform transactions in the account’s name.
In practice, this means that only the account’s smart contract can transfer assets, create sub-accounts, or update its own code.
Locking an account can be useful to implement immutable contracts.
Reference
Access keys: https://docs.near.org/concepts/basics/accounts/access-keys
What is a NEAR account: https://npkguild.medium.com/into-near-what-is-a-near-account-b265f38da274
FOR MORE INFORMATION FOLLOW US AT
Twitter :https://twitter.com/nearprotocolng?s=21
Telegram: https://t.me/NPKGUILD
website: https://nearnigeria.org/