near-api-js - v7.5.3
    Preparing search index...

    Class Account

    This class allows to access common account information. If a Signer is provider, then the account can be used to perform all common actions such as transferring tokens and calling functions

    Index
    • Creates a client for an account; does not create the account on-chain.

      Parameters

      • accountId: string

        Account to query or sign transactions for.

      • provider: string | Provider

        RPC provider instance or endpoint URL.

      • Optionalsigner: KeyPairString | Signer

        Optional signer or curve-prefixed secret key. Read-only operations do not require one.

      Returns Account

    accountId: string
    provider: Provider
    • Call a function on a smart contract and return parsed transaction result

      Type Parameters

      Parameters

      • params: CallFunctionArgs

        Call function parameters

        • Optionalargs?: Uint8Array<ArrayBufferLike> | Record<string, any>
        • contractId: string
        • Optionaldeposit?: string | number | bigint
        • Optionalgas?: string | number | bigint
        • methodName: string
        • OptionalwaitUntil?: TxExecutionStatus

      Returns Promise<T>

      The final success value decoded as JSON when possible, otherwise as a string. Returns null when no success value is available at the requested execution milestone.

      If signing, submission, or transaction execution fails.

      callFunctionRaw for logs, receipt outcomes, and transaction metadata.

    • Call a function on a smart contract and return raw transaction outcome

      Parameters

      • params: CallFunctionArgs

        Call function parameters

        • Optionalargs?: Uint8Array<ArrayBufferLike> | Record<string, any>
        • contractId: string
        • Optionaldeposit?: string | number | bigint
        • Optionalgas?: string | number | bigint
        • methodName: string
        • OptionalwaitUntil?: TxExecutionStatus

      Returns Promise<RpcTransactionResponse>

      The RPC transaction response, including execution logs and receipt outcomes when available.

      If signing, submission, or transaction execution fails.

    • Creates a new NEAR account with a given ID and public key.

      This method can create two types of accounts:

      1. Top-level accounts of the form name.tla (e.g., bob.near):

      2. Sub-accounts of the current account (e.g., sub.ana.near):

        • The new account ID must end with the current account ID
        • Example: If your account is ana.near, you can create sub.ana.near

      Creating name.tla outside this account's subtree calls create_account on the tla account; that account must implement the account-creation contract method.

      Parameters

      • options: CreateAccountArgs

        Account creation options

        • OptionalnearToTransfer?: string | number | bigint
        • newAccountId: string
        • publicKey: string | PublicKey

      Returns Promise<RpcTransactionResponse>

    • Creates or initializes a NEP-616 account at the ID derived from its state initialization.

      Parameters

      • options: { deposit?: string | bigint; stateInit: DeterministicStateInit }

        Initialization and funding options.

        • Optionaldeposit?: string | bigint

          Storage deposit in yoctoNEAR. Defaults to 0; excess is refunded by the protocol.

        • stateInit: DeterministicStateInit

          Global contract reference and raw initial storage used to derive the account ID.

      Returns Promise<RpcTransactionResponse>

      The submitted transaction response. This account's signer pays for initialization.

    • Initializes a protocol-88 universal account at the ID derived from the supplied state-init bytes.

      Parameters

      • options: { deposit?: string | bigint; stateInit: Uint8Array }

        Initialization and funding options.

        • Optionaldeposit?: string | bigint

          Deposit in yoctoNEAR. Defaults to 0.

        • stateInit: Uint8Array

          Raw versioned state-init bytes, such as the result of UniversalStateInit.encode().

      Returns Promise<RpcTransactionResponse>

      The submitted transaction response. This account's signer pays for initialization.

      The bytes are forwarded unchanged; the node validates the state initialization.

    • Deletes the account, transferring all remaining NEAR to a beneficiary account

      Important: Deleting an account does not transfer FTs or NFTs

      Parameters

      • beneficiaryId: string

        Will receive the account's remaining balance

      Returns Promise<RpcTransactionResponse>

    • Deploy a global contract that can be reused by multiple accounts

      Parameters

      • code: Uint8Array

        The compiled contract code bytes

      • deployMode: "accountId" | "codeHash"

        Deploy mode - "codeHash" for immutable contracts, "accountId" for updateable contracts

      Returns Promise<RpcTransactionResponse>

    • Calls Provider.viewAccessKeyList to retrieve one page of the account's keys. Pass the returned last_key unchanged as afterKey to request the next page. Without pagination options, accounts exceeding the node's key limit may be rejected.

      Parameters

      • options: { afterKey?: string; limit?: number } = {}

        Optional page size and cursor

      Returns Promise<AccessKeyList & { block_hash: string; block_height: number }>

    • Calls Provider.viewContractState to retrieve the keys and values stored on the account's contract

      Parameters

      • Optionalprefix: string

      Returns Promise<ViewStateResult & { block_hash: string; block_height: number }>

    • Allows to set the signer used to control the account

      Parameters

      • signer: Signer

        holds the private key and can sign Transactions

      Returns void

    • This function simply calls the signNep413Message method of the Signer

      Parameters

      • args: SignNep413MessageArgs

        Nep413 message signing arguments

        • OptionalcallbackUrl?: string
        • message: string
        • nonce: Uint8Array
        • recipient: string

      Returns Promise<SignedMessage>

      The signed message with account ID, public key, and raw signature bytes; no transaction is submitted.

      This method is deprecated and will be removed in future versions. Please use signMessage from near-api-js/nep413 to sign NEP-413 messages.

    • Transfers a token to the specified receiver.

      Supports sending either the native NEAR token or any supported Fungible Token (FT).

      Parameters

      Returns Promise<RpcTransactionResponse>

      The transfer transaction response.

      For fungible tokens, an unregistered receiver is first registered in a separate transaction funded by this account. Registration and transfer are not atomic.

    • Fund a gas key balance. The gas key can belong to any account

      Parameters

      • accountId: string

        The account that owns the gas key

      • publicKey: string | PublicKey

        The public key of the gas key

      • amount: string | number | bigint

        The amount of yoctoNEAR to transfer to the gas key

      Returns Promise<RpcTransactionResponse>

    • Use a previously deployed global contract on this account

      Parameters

      • contractIdentifier: { accountId: string } | { codeHash: string | Uint8Array<ArrayBufferLike> }

        The global contract identifier - either { accountId: string } or { codeHash: string | Uint8Array }

      Returns Promise<RpcTransactionResponse>