Access Keys
The RPC API enables you to retrieve information about an account's access keys. Access keys are cryptographic keys that allow actions to be performed on behalf of an account, with different permission levels for security.
Access Key Types
- Full Access Keys: Can perform any action on the account, including deploying contracts, managing other keys, and transferring funds
- Function Call Keys: Restricted to calling specific contract methods with limited allowance for gas fees
Quick Reference
Method | Endpoint | Purpose |
---|---|---|
view_access_key | Query single key | Get details of a specific access key |
view_access_key_list | Query all keys | List all access keys for an account |
single_access_key_changes | Track specific changes | Monitor changes to specific keys |
all_access_key_changes | Track all changes | Monitor all key changes for accounts |
View access key
Description
Returns information about a single access key for a given account.
If permission
of the key is FunctionCall
, it will return more details such as the allowance
, receiver_id
, and method_names
.
Example
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_access_key",
"finality": "final",
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
}
}
const response = await near.connection.provider.query({
request_type: 'view_access_key',
finality: 'final',
account_id: 'account.rpc-examples.testnet',
public_key: 'ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd',
});
http POST https://rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=query \
params:='{
"request_type": "view_access_key",
"finality": "final",
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
}'
Try it out on Lantstool
Loading...
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "J1zkrK8sHuzzV8pkXsEPrZH7SQZeJ2NSEs9L1hSWzVgg",
"block_height": 187316844,
"nonce": 187309654000001,
"permission": {
"FunctionCall": {
"allowance": "149788200694421800000000",
"method_names": [
"write_record",
"get_record",
"get_greeting",
"__contract_abi",
"contract_source_metadata"
],
"receiver_id": "contract.rpc-examples.testnet"
}
}
},
"id": "dontcare"
}
Error handling:
When making RPC API requests, you may encounter various errors related to network configuration, rate limiting, or request formatting. For comprehensive information about error types, causes, and solutions, see the RPC Errors documentation.
View access key list
Description
Returns all access keys for a given account.
Example
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_access_key_list",
"finality": "final",
"account_id": "account.rpc-examples.testnet"
}
}
const response = await near.connection.provider.query({
request_type: 'view_access_key_list',
finality: 'final',
account_id: 'account.rpc-examples.testnet',
});
http POST https://rpc.testnet.near.org \
jsonrpc=2.0 \
id="dontcare" \
method=query \
params:='{
"request_type": "view_access_key_list",
"finality": "final",
"account_id": "account.rpc-examples.testnet"
}'
Try it out on Lantstool
Loading...
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "29G6xeV4ufkVsY24YZPfiRwLMTNoKrAMitrjg6nvVZqq",
"block_height": 187319080,
"keys": [
{
"access_key": {
"nonce": 187309654000000,
"permission": "FullAccess"
},
"public_key": "ed25519:vJBU18AtvePANmepMoY3rtV3wt1RHwqoktak82E4d2M"
},
{
"access_key": {
"nonce": 187309654000001,
"permission": {
"FunctionCall": {
"allowance": "149788200694421800000000",
"method_names": [
"write_record",
"get_record",
"get_greeting",
"__contract_abi",
"contract_source_metadata"
],
"receiver_id": "contract.rpc-examples.testnet"
}
}
},
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
}
]
},
"id": "dontcare"
}
Error handling:
When making RPC API requests, you may encounter various errors related to network configuration, rate limiting, or request formatting. For comprehensive information about error types, causes, and solutions, see the RPC Errors documentation.
View access key changes (single)
Description
Returns individual access key changes in a specific block. You can query multiple
keys by passing an array of objects containing the account_id
and public_key
.
Example
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "changes",
"params": {
"changes_type": "single_access_key_changes",
"keys": [
{
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
}
],
"block_id": "6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w"
}
}
const response = await near.connection.provider.singleAccessKeyChanges(
[
{
account_id: 'account.rpc-examples.testnet',
public_key: 'ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd',
},
],
{ blockId: '6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w' },
);
http POST https://archival-rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=changes \
params:='{
"changes_type": "single_access_key_changes",
"keys": [
{
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
}
],
"block_id": "6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w"
}'
Try it out on Lantstool
Loading...
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w",
"changes": [
{
"cause": {
"tx_hash": "J3KbUXF9YPu2eGnbDCACxGvmMDZMdP7acGYhVLHGu9y2",
"type": "transaction_processing"
},
"change": {
"access_key": {
"nonce": 187309654000001,
"permission": {
"FunctionCall": {
"allowance": "142924791772640836536480",
"method_names": [
"write_record",
"get_record",
"get_greeting",
"__contract_abi",
"contract_source_metadata"
],
"receiver_id": "contract.rpc-examples.testnet"
}
}
},
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
},
"type": "access_key_update"
}
]
},
"id": "dontcare"
}
Error handling:
When making RPC API requests, you may encounter various errors related to network configuration, rate limiting, or request formatting. For comprehensive information about error types, causes, and solutions, see the RPC Errors documentation.
View access key changes (all)
Description
Returns changes to all access keys of a specific block.
Multiple accounts can be queried by passing an array of account_ids
.
Example
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "changes",
"params": {
"changes_type": "all_access_key_changes",
"account_ids": ["account.rpc-examples.testnet"],
"block_id": 187309655
}
}
const response = await near.connection.provider.accessKeyChanges(['account.rpc-examples.testnet'], {
blockId: 187309655,
});
http POST https://archival-rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=changes \
params:='{
"changes_type": "all_access_key_changes",
"account_ids": ["account.rpc-examples.testnet"],
"block_id": 187309655
}'
Try it out on Lantstool
Loading...
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "6EDgS3zF9aoBMfdHqthQTQtudt7JzdLBbkTb6Jn4wfP9",
"changes": [
{
"cause": {
"receipt_hash": "9meU2ibDyJS2ga4se7j5knsWetKrXaw5qBpwrYgN1Qeh",
"type": "receipt_processing"
},
"change": {
"access_key": {
"nonce": 187309654000000,
"permission": "FullAccess"
},
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:vJBU18AtvePANmepMoY3rtV3wt1RHwqoktak82E4d2M"
},
"type": "access_key_update"
},
{
"cause": {
"receipt_hash": "9meU2ibDyJS2ga4se7j5knsWetKrXaw5qBpwrYgN1Qeh",
"type": "receipt_processing"
},
"change": {
"access_key": {
"nonce": 187309654000000,
"permission": {
"FunctionCall": {
"allowance": "150000000000000000000000",
"method_names": [
"write_record",
"get_record",
"get_greeting",
"__contract_abi",
"contract_source_metadata"
],
"receiver_id": "contract.rpc-examples.testnet"
}
}
},
"account_id": "account.rpc-examples.testnet",
"public_key": "ed25519:EddTahJwZpJjYPPmat7DBm1m2vdrFBzVv7e3T4hzkENd"
},
"type": "access_key_update"
}
]
},
"id": "dontcare"
}
Error handling:
When making RPC API requests, you may encounter various errors related to network configuration, rate limiting, or request formatting. For comprehensive information about error types, causes, and solutions, see the RPC Errors documentation.
Best Practices
- Use specific queries: Use
view_access_key
when you know the exact key instead of listing all keys - Cache results: Access key information does not change frequently, consider caching
- Batch operations: When checking multiple keys, use
single_access_key_changes
with multiple keys - Archival nodes: Only use archival endpoints when historical data is required