This class provides common account related RPC calls including signing transactions with a KeyPair.

Hierarchy (View Summary)

Constructors

  • Parameters

    • connection: Connection
    • accountId: string
    • options: any

    Returns Account2FA

Properties

accountId: string
connection: Connection
getCode: getCodeFunction
helperUrl: string
onAddRequestResult: (any: any) => any
onConfirmResult: (any: any) => any
sendCode: sendCodeFunction

Account2FA has options object where you can provide callbacks for:

  • sendCode: how to send the 2FA code in case you don't use NEAR Contract Helper
  • getCode: how to get code from user (use this to provide custom UI/UX for prompt of 2FA code)
  • onResult: the tx result after it's been confirmed by NEAR Contract Helper

storage: any
verifyCode: verifyCodeFunction

Methods

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

    expand this API to support more options.

  • This method submits a canary transaction that is expected to always fail in order to determine whether the contract currently has valid multisig state and whether it is initialized. The canary transaction attempts to delete a request at index u32_max and will go through if a request exists at that index. a u32_max + 1 and -1 value cannot be used for the canary due to expected u32 error thrown before deserialization attempt.

    Parameters

    • OptionalcontractBytes: Uint8Array

      The bytecode of the multisig contract.

    Returns Promise<{ codeStatus: MultisigCodeStatus; stateStatus: MultisigStateStatus }>

    A promise that resolves to the status of the code and state.

  • Parameters

    • newAccountId: string

      NEAR account name to be created

    • publicKey: string | PublicKey

      A public key created from the masterAccount

    • amount: bigint

    Returns Promise<FinalExecutionOutcome>

  • Create a new account and deploy a contract to it

    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>

  • Parameters

    • beneficiaryId: string

      The NEAR account that will receive the remaining Ⓝ balance from the account being deleted

    Returns Promise<FinalExecutionOutcome>

  • Delete all multisig requests associated with the account.

    Returns Promise<void>

    A promise that resolves when all requests are deleted.

  • Parameters

    • publicKey: string | PublicKey

      The public key to be deleted

    Returns Promise<FinalExecutionOutcome>

  • Delete a multisig request by its ID.

    Parameters

    • request_id: any

      The ID of the multisig request to be deleted.

    Returns Promise<FinalExecutionOutcome>

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

  • Delete unconfirmed multisig requests associated with the account.

    Returns Promise<void>

    A promise that resolves when unconfirmed requests are deleted.

  • Parameters

    • data: Uint8Array

      The compiled contract code

    Returns Promise<FinalExecutionOutcome>

  • Deploy a multisig contract with 2FA and handle the deployment process.

    Parameters

    • contractBytes: Uint8Array

      The bytecode of the multisig contract.

    Returns Promise<FinalExecutionOutcome>

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

  • Disable 2FA with the option to clean up contract state.

    Parameters

    • options: { cleanupContractBytes?: Uint8Array; contractBytes: Uint8Array }

      Options for disabling 2FA.

      • OptionalcleanupContractBytes?: Uint8Array

        The bytecode of the cleanup contract (optional).

      • contractBytes: Uint8Array

        The bytecode of the contract to deploy.

    Returns Promise<FinalExecutionOutcome>

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

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

    Parameters

    • receiverId: string

      currently unused (see todo)

    • actions: Action[]

      currently unused (see todo)

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

    { publicKey PublicKey; accessKey: AccessKeyView }

    Find matching access key based on transaction (i.e. receiverId and actions)

  • Execute a function call.

    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

      • OptionaljsContract?: boolean

        Is contract from JS SDK, automatically encodes args from JS SDK to binary.

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

  • Retrieves cleanup actions for disabling 2FA.

    Parameters

    • cleanupContractBytes: Uint8Array

      The bytecode of the cleanup contract.

    Returns Promise<Action[]>

    • A promise that resolves to an array of cleanup actions.
  • Retrieves key conversion actions for disabling 2FA.

    Returns Promise<Action[]>

    • A promise that resolves to an array of key conversion actions.
  • Gets the 2FA method (kind and detail).

    Returns Promise<{ detail: any; kind: any }>

    A promise that resolves to the 2FA method.

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

    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.

    Returns Promise<ActiveDelegatedStakeBalance>

  • Returns Promise<string>

  • Returns Connection

  • Retrieves recovery methods for the account.

    Returns Promise<{ accountId: string; data: Response }>

    • A promise that resolves to recovery methods data.
  • Returns any

  • Returns Promise<string[]>

  • Sends a signed JSON request to a specified path.

    Parameters

    • path: any

      The path for the request.

    • body: any

      The request body.

    Returns Promise<Response>

    • A promise that resolves to the response from the helper.
  • Prompts the user to enter and verify the 2FA code.

    Returns any

    • A promise that resolves to the verification result.
  • Default implementation for sending the 2FA code.

    Returns Promise<any>

    • A promise that resolves to the request ID.
  • Parameters

    • receiverId: string

      NEAR account receiving Ⓝ

    • amount: bigint

      Amount to send in yoctoⓃ

    Returns Promise<FinalExecutionOutcome>

  • Parameters

    • data: any

    Returns any

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

    Parameters

    • options: SignAndSendTransactionOptions

      Options for the transaction.

      Options used to initiate sining and sending transactions

      • actions: Action[]
      • receiverId: string
      • OptionalreturnError?: boolean
      • 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 transaction.

  • Sign and send a transaction with the multisig account as the sender.

    Parameters

    • receiverId: string

      The NEAR account ID of the transaction receiver.

    • actions: Action[]

      The list of actions to be included in the transaction.

    Returns Promise<FinalExecutionOutcome>

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

  • Generates a signature for the latest finalized block.

    Returns Promise<{ blockNumber: string; blockNumberSignature: string }>

    • A promise that resolves to the signature information.
  • Compose and sign a SignedDelegate action to be executed in a transaction on behalf of this Account instance

    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>

  • Verify the 2FA code using the default method.

    Parameters

    • securityCode: string

      The security code to verify.

    Returns Promise<Response>

    A promise that resolves to the verification result.

  • Invoke a contract view function using the RPC API.

    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

      • OptionaljsContract?: boolean

        Is contract from JS SDK, automatically encodes args from JS SDK to binary.

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

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

    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 "optimistic" block (i.e. not necessarily finalized).

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