NearApi.RPC.AccessKeys
Setup
System.put_env("NEAR_PUBLIC_KEY", "ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW")
System.put_env("NEAR_NODE_URL", "https://rpc.testnet.near.org")
:ok
NearApi.RPC.AccessKeys.view_access_key/3
Returns information about a single access key for given account.
If permission
of the key is FunctionCall
, it will return more details such as the allowance
, receiver_id
, and method_names
.
Parameters are account_id
, block_id
.
When block_id
is nil
- we API returns information about latest block of the account according to finality
parameter
Success
NearApi.RPC.AccessKeys.view_access_key("client.chainlink.testnet")
{:ok,
%{
"id" => "dontcare",
"jsonrpc" => "2.0",
"result" => %{
"block_hash" => "GeBZuqFJZ4h6F4VrUgZq2nXLMCkk9t7eyMsT5mrYM2WC",
"block_height" => 85946674,
"nonce" => 184,
"permission" => %{
"FunctionCall" => %{
"allowance" => "17926238097406453100000000",
"method_names" => ["get_token_price"],
"receiver_id" => "client.chainlink.testnet"
}
}
}
}}
When we specify block_id
API returns access key for given block
NearApi.RPC.AccessKeys.view_access_key(
"client.chainlink.testnet",
"AseZCt1TxexkYcBX6hwH9KyK9pzGRYzwautpQbbqwLB5"
)
{:ok,
%{
"id" => "dontcare",
"jsonrpc" => "2.0",
"result" => %{
"block_hash" => "AseZCt1TxexkYcBX6hwH9KyK9pzGRYzwautpQbbqwLB5",
"block_height" => 68795818,
"nonce" => 139,
"permission" => %{
"FunctionCall" => %{
"allowance" => "17989377927208900227148640",
"method_names" => ["get_token_price"],
"receiver_id" => "client.chainlink.testnet"
}
}
}
}}
Errors
When account_id
is invalid API returns error struct REQUEST_VALIDATION_ERROR
, where response
contains raw response from the NEAR platform.
Passed arguments can’t be parsed by JSON RPC server (missing arguments, wrong format, etc.)
NearApi.RPC.AccessKeys.view_access_key("client.chainlink__.testnet")
{:error,
%{
error_cause: "PARSE_ERROR",
error_code: -32700,
error_description: "Failed parsing args: [client.chainlink__.testnet]: the value has invalid characters for account ID",
error_message: "Parse error",
error_type: "REQUEST_VALIDATION_ERROR",
response: %{
"error" => %{
"cause" => %{
"info" => %{
"error_message" => "Failed parsing args: [client.chainlink__.testnet]: the value has invalid characters for account ID"
},
"name" => "PARSE_ERROR"
},
"code" => -32700,
"data" => "Failed parsing args: [client.chainlink__.testnet]: the value has invalid characters for account ID",
"message" => "Parse error",
"name" => "REQUEST_VALIDATION_ERROR"
},
"id" => "dontcare",
"jsonrpc" => "2.0"
}
}}
When account_id
is valid but the you’re using a key without permissions to this account, you’ll get an :error
struct with simple error_message
and raw response in response
field. (Note - NEAR platform returns a success
reponse in this case but I wrapped this one as an error anyway)
NearApi.RPC.AccessKeys.view_access_key("client.chainlink404.testnet")
{:error,
%{
error_message: "access key ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW does not exist while viewing",
error_type: "SOFT_ERROR",
response: %{
"id" => "dontcare",
"jsonrpc" => "2.0",
"result" => %{
"block_hash" => "9Bm4MVxMaQus6FcadL3UuBJJQ6BumzQFYNuezsYGejyS",
"block_height" => 77410756,
"error" => "access key ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW does not exist while viewing",
"logs" => []
}
}
}}
NearApi.RPC.AccessKeys.view_access_key_list/3
Returns all access keys for a given account.
NearApi.RPC.AccessKeys.view_access_key("client.chainlink.testnet")
{:ok,
%{
"id" => "dontcare",
"jsonrpc" => "2.0",
"result" => %{
"block_hash" => "HCHVFxYXxdMdsHxLrNXPiEvqMAzPWNTCANTSFABRHoLx",
"block_height" => 77410777,
"nonce" => 157,
"permission" => %{
"FunctionCall" => %{
"allowance" => "18074888454317128100000000",
"method_names" => ["get_token_price"],
"receiver_id" => "client.chainlink.testnet"
}
}
}
}}
When we specify block_id
:
NearApi.RPC.AccessKeys.view_access_key(
"client.chainlink.testnet",
"AseZCt1TxexkYcBX6hwH9KyK9pzGRYzwautpQbbqwLB5"
)
{:ok,
%{
"id" => "dontcare",
"jsonrpc" => "2.0",
"result" => %{
"block_hash" => "AseZCt1TxexkYcBX6hwH9KyK9pzGRYzwautpQbbqwLB5",
"block_height" => 68795818,
"nonce" => 139,
"permission" => %{
"FunctionCall" => %{
"allowance" => "17989377927208900227148640",
"method_names" => ["get_token_price"],
"receiver_id" => "client.chainlink.testnet"
}
}
}
}}