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

Constructors

  • Parameters

    • accountId: string
    • provider: Provider
    • Optionalsigner: Signer

    Returns Account

Properties

accountId: string
provider: Provider

Methods

  • Add a full access key to the account

    Parameters

    • publicKey: string | PublicKey

      The public key to be added

    Returns Promise<FinalExecutionOutcome>

  • Parameters

    • options: {
          allowance: string | number | bigint;
          contractId: string;
          methodNames: string[];
          publicKey: string | PublicKey;
      }
      • allowance: string | number | bigint

        The amount of NEAR this key can expend in gas

      • contractId: string

        The contract that this key can call

      • methodNames: string[]

        The methods this key is allowed to call

      • publicKey: string | PublicKey

        The key to add to the account

    Returns Promise<FinalExecutionOutcome>

  • Parameters

    • publicKey: string | PublicKey

      A public key to be associated with the contract

    • OptionalcontractId: string

      NEAR account where the contract is deployed

    • OptionalmethodNames: string | string[]

      The method names on the contract that should be allowed to be called. Pass null for no method names and '' or [] for any method names.

    • Optionalamount: bigint

      Payment in yoctoⓃ that is sent to the contract during this function call

    Returns Promise<FinalExecutionOutcome>

    please use addFullAccessKey or addFunctionAccessKey

    expand this API to support more options.

  • Call a function on a smart contract

    Parameters

    • options: {
          args: Uint8Array | Record<string, any>;
          contractId: string;
          deposit?: string | number | bigint;
          gas?: string | number | bigint;
          methodName: string;
      }
      • args: Uint8Array | Record<string, any>

        Arguments, either as a valid JSON Object or a raw Uint8Array

      • contractId: string

        The contract in which to call the function

      • Optionaldeposit?: string | number | bigint

        (optional) Amount of NEAR Tokens to attach to the call (default 0)

      • Optionalgas?: string | number | bigint

        (optional) Amount of GAS to use attach to the call (default 30TGas)

      • methodName: string

        The method that will be called

    Returns Promise<string | number | object>

  • 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

    Parameters

    • newAccountId: string

      the new account to create (e.g. bob.near or sub.ana.near)

    • publicKey: string | PublicKey

      the public part of the key that will control the account

    • OptionalnearToTransfer: string | number | bigint

      how much NEAR to transfer to the account in yoctoNEAR (default: 0)

    Returns Promise<FinalExecutionOutcome>

  • Parameters

    • contractId: string

      NEAR account where the contract is deployed

    • publicKey: string | PublicKey

      The public key to add to the created contract account

    • data: Uint8Array

      The compiled contract code

    • amount: bigint

      of NEAR to transfer to the created contract account. Transfer enough to pay for storage https://docs.near.org/docs/concepts/storage-staking

    Returns Promise<Account>

    instead please create a transaction with the actions bellow and broadcast it to the network

    1. createAccount
    2. transfer some tokens
    3. deployContract
    4. (optional) addKey
    5. (optional) functionCall to an initialization function

    Create a new account and deploy a contract to it

  • Create a meta transaction ready to be signed by a Signer

    Parameters

    • receiverId: string

      NEAR account receiving the transaction

    • actions: Action[]

      list of actions to perform as part of the meta transaction

    • blockHeightTtl: number

      number of blocks after which a meta transaction will expire if not processed

    • publicKey: string | PublicKey

    Returns Promise<DelegateAction>

  • Create a signed MetaTransaction that can be broadcasted to a relayer

    Parameters

    • receiverId: string

      NEAR account receiving the transaction

    • actions: Action[]

      list of actions to perform as part of the meta transaction

    • OptionalblockHeightTtl: number

      number of blocks after which a meta transaction will expire if not processed

    Returns Promise<[Uint8Array, SignedDelegate]>

  • Create a signed transaction ready to be broadcast by a Provider

    Parameters

    • receiverId: string
    • actions: Action[]

    Returns Promise<SignedTransaction>

  • Creates a sub account of this account. For example, if the account is ana.near, you can create sub.ana.near.

    Parameters

    • accountOrPrefix: string

      a prefix (e.g. sub) or the full sub-account (sub.ana.near)

    • publicKey: string | PublicKey

      the public part of the key that will control the account

    • OptionalnearToTransfer: string | number | bigint

      how much NEAR to transfer to the account (default: 0)

    Returns Promise<FinalExecutionOutcome>

  • Create a transaction that can be later signed with a Signer

    Parameters

    • receiverId: string

      Account against which to perform the actions

    • actions: Action[]

      Actions to perform

    • publicKey: string | PublicKey

      The public part of the key that will be used to sign the transaction

    Returns Promise<Transaction>

  • 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<FinalExecutionOutcome>

  • Parameters

    • publicKey: string | PublicKey

      The public key to be deleted

    Returns Promise<FinalExecutionOutcome>

  • Deploy a smart contract in the account

    Parameters

    • code: Uint8Array

      The compiled contract code bytes

    Returns Promise<FinalExecutionOutcome>

  • @deprecated, accounts will no longer handle keystores

    Finds the AccessKeyView associated with the accounts PublicKey stored in the Keystore.

    Parameters

    • receiverId: string

      currently unused

    • actions: Action[]

      currently unused

    Returns Promise<{ accessKey: AccessKeyView; publicKey: PublicKey }>

    { publicKey PublicKey; accessKey: AccessKeyView }

  • Parameters

    • options: ChangeFunctionCallOptions

      The options for the function call.

      Options used to initiate a function call (especially a change function call)

      • Optionalargs?: object

        named arguments to pass the method { messageText: 'my message' }

      • OptionalattachedDeposit?: bigint

        amount of NEAR (in yoctoNEAR) to send together with the call

      • contractId: string

        The NEAR account id where the contract is deployed

      • Optionalgas?: bigint

        max amount of gas that method call can use

      • methodName: string

        The name of the method to invoke

      • Optionalstringify?: (input: any) => Buffer

        Convert input arguments into bytes array.

      • OptionalwalletCallbackUrl?: string

        Callback url to send the NEAR Wallet if using it to sign transactions.

        RequestSignTransactionsOptions

      • OptionalwalletMeta?: string

        Metadata to send the NEAR Wallet if using it to sign transactions.

        RequestSignTransactionsOptions

    Returns Promise<FinalExecutionOutcome>

    A promise that resolves to the final execution outcome of the function call.

    please use callFunction instead

    Execute a function call.

  • Calls Provider.viewAccessKey to retrieve information for a specific key in the account

    Parameters

    Returns Promise<AccessKeyView>

  • Calls Provider.viewAccessKeyList to retrieve the account's keys

    Returns Promise<AccessKeyList>

  • Returns Promise<{ authorizedApps: AccountAuthorizedApp[] }>

    Returns a list of authorized apps

    update the response value to return all the different keys, not just app keys.

  • Returns the NEAR tokens balance and validators of a given account that is delegated to the staking pools that are part of the validators set in the current epoch.

    Returns Promise<ActiveDelegatedStakeBalance>

    NOTE: If the tokens are delegated to a staking pool that is currently on pause or does not have enough tokens to participate in validation, they won't be accounted for.

  • Parameters

    • Optionaltoken: NativeToken | FungibleToken

      The token to check the balance of. Defaults to Native NEAR.

    Returns Promise<bigint>

    The available balance of the account in units (e.g. yoctoNEAR).

  • @deprecated, accounts no longer use Connections since it's deprecated too

    Returns Connection

  • Calls Provider.viewContractCode to retrieve the account's contract code and its hash

    Returns Promise<ContractCodeView>

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

    Parameters

    • Optionalprefix: string

    Returns Promise<ContractStateView>

  • Returns Signer

  • Returns an overview of the account's state, including the account's balance, storage usage, and code hash

    Returns Promise<AccountState>

  • Parameters

    • txHash: string | Uint8Array

    Returns Promise<FinalExecutionOutcome>

    use instead Provider.viewTransactionStatus

  • Parameters

    • receiverId: string

      NEAR account receiving Ⓝ

    • amount: bigint

      Amount to send in yoctoⓃ

    Returns Promise<FinalExecutionOutcome>

    please instead use transfer

  • Allows to set the signer used to control the account

    Parameters

    • signer: Signer

      holds the private key and can sign Transactions

    Returns void

  • Creates a transaction, signs it and broadcast it to the network

    Parameters

    • __namedParameters: {
          actions: Action[];
          receiverId: string;
          throwOnFailure?: boolean;
          waitUntil?: TxExecutionStatus;
      }

    Returns Promise<FinalExecutionOutcome>

    A promise that resolves to the final execution outcome of the transaction.

  • Parameters

    Returns Promise<FinalExecutionOutcome>

    A promise that resolves to the final execution outcome of the transaction.

    please instead use signAndSendTransaction

    Sign a transaction to perform a list of actions and broadcast it using the RPC API.

  • Parameters

    • __namedParameters: {
          throwOnFailure?: boolean;
          transactions: { actions: Action[]; receiverId: string }[];
          waitUntil?: TxExecutionStatus;
      }

    Returns Promise<FinalExecutionOutcome[]>

  • Parameters

    • options: SignedDelegateOptions

      Options for the transaction.

      • actions

        Actions to be included in the meta transaction

      • blockHeightTtl

        Number of blocks past the current block height for which the SignedDelegate action may be included in a meta transaction

      • receiverId

        Receiver account of the meta transaction

    Returns Promise<SignedDelegate>

    please use Account.createSignedMetaTransaction instead

    Compose and sign a SignedDelegate action to be executed in a transaction on behalf of this Account instance

  • This function simply calls the signNep413Message method of the Signer

    Parameters

    • options: { callbackUrl?: string; message: string; nonce: Uint8Array; recipient: string }
      • OptionalcallbackUrl?: string

        (optional) Deprecated parameter used only by browser wallets

      • message: string

        The message to be signed (e.g. "authenticating")

      • nonce: Uint8Array

        A challenge sent by the recipient

      • recipient: string

        Who will receive the message (e.g. auth.app.com)

    Returns Promise<SignedMessage>

  • Parameters

    • receiverId: string

      NEAR account receiving the transaction

    • actions: Action[]

      list of actions to perform as part of the transaction

    • Optionalopts: { signer: Signer }

    Returns Promise<[Uint8Array, SignedTransaction]>

    use $createSignedTransaction Create a signed transaction which can be broadcast to the network

  • Transfers a token to the specified receiver.

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

    Parameters

    • __namedParameters: {
          amount: string | number | bigint;
          receiverId: string;
          token?: NativeToken | FungibleToken;
      }

    Returns Promise<FinalExecutionOutcome>

  • Parameters

    • options: ViewFunctionCallOptions

      Function call options.

      Options used to initiate a function call (especially a change function call)

      • Optionalargs?: object

        named arguments to pass the method { messageText: 'my message' }

      • OptionalattachedDeposit?: bigint

        amount of NEAR (in yoctoNEAR) to send together with the call

      • OptionalblockQuery?: BlockReference
      • contractId: string

        The NEAR account id where the contract is deployed

      • Optionalgas?: bigint

        max amount of gas that method call can use

      • methodName: string

        The name of the method to invoke

      • Optionalparse?: (response: Uint8Array) => any
      • Optionalstringify?: (input: any) => Buffer

        Convert input arguments into bytes array.

    Returns Promise<any>

    please use Provider.callFunction instead

    Invoke a contract view function using the RPC API.

  • Parameters

    • prefix: string | Uint8Array

      allows to filter which keys should be returned. Empty prefix means all keys. String prefix is utf-8 encoded.

    • OptionalblockQuery: BlockReference

      specifies which block to query state at. By default returns last DEFAULT_FINALITY block (i.e. not necessarily finalized).

    Returns Promise<{ key: Buffer; value: Buffer }[]>

    please use getContractState instead

    Returns the state (key value pairs) of this account's contract based on the key prefix. Pass an empty string for prefix if you would like to return the entire state.