Add Access Key

Add Access Key

Overview

This n8n node, Add Access Key, is designed to interact with the NEAR blockchain. It allows users to add an access key to a specified NEAR account (contract), enabling programmatic or restricted access to contract methods. This is particularly useful for automating contract interactions, delegating limited permissions to third-party services, or managing multi-user dApps.

Common scenarios:

  • Granting a new public key permission to call specific contract methods.
  • Automating wallet or contract management tasks in NEAR-based applications.
  • Delegating access for bots, scripts, or external services to interact with a NEAR smart contract.

Example use cases:

  • A dApp admin wants to allow a backend service to call only certain methods on their contract.
  • Rotating access keys for enhanced security without manual intervention.

Properties

Name Type Meaning
Network ID String The NEAR network to connect to (e.g., "mainnet" or "testnet").
Private Key to Sign String The private key used to sign the transaction that adds the access key.
Signer Account ID String The NEAR account ID that will sign and authorize the addition of the new key.
Public Key to Add String The public key to be added as an access key to the contract.
Contract Account ID String (Optional) The NEAR account where the contract is deployed. If omitted, the key is added to the signer’s own account.
Method Names as JSON String (Optional) JSON array of method names the new key is allowed to call. Use null for no restrictions, or []/empty string for all methods.
Attached NEAR Amount String (Optional) Amount of yoctoⓃ (smallest NEAR unit) attached to the function call. Used for payable contract methods or storage requirements.

Output

The node outputs a single item per input, with the following structure in the json field:

{
  "result": { /* Result object returned by NEAR's addKey operation */ }
}
  • The exact contents of result depend on the NEAR API response for the addKey operation. Typically, it includes transaction details or confirmation of the key addition.

If an error occurs and "Continue On Fail" is enabled, the output may include:

{
  "error": { /* Error object */ },
  "pairedItem": <index>
}

Dependencies

  • External Services: Requires access to the NEAR blockchain (either mainnet or testnet).
  • API Keys: Needs the private key of the NEAR account that will sign the transaction.
  • n8n Configuration: No special environment variables required, but internet access to NEAR RPC endpoints is necessary.

Troubleshooting

Common issues:

  • Invalid Private Key: If the provided private key is incorrect or not associated with the signer account, the operation will fail.
  • Malformed Method Names: If "Method Names as JSON" is not valid JSON, parsing will throw an error.
  • Insufficient Balance: If the signer account lacks sufficient funds to pay for the transaction or attached amount, the operation will fail.
  • Network Mismatch: Using a key or account from one network (e.g., testnet) on another (e.g., mainnet) will result in errors.

Error messages:

  • "Unexpected token ... in JSON at position ...": Indicates invalid JSON in "Method Names as JSON". Ensure you provide a valid JSON array or null.
  • "Account does not exist" or "Access denied": Check that the signer account exists and has the correct permissions.
  • "Insufficient funds": Make sure the signer account has enough NEAR tokens.

Resolution steps:

  • Double-check all account IDs and keys.
  • Validate your JSON input for method names.
  • Ensure the correct network is selected.
  • Confirm the account has enough balance.

Links and References


Discussion