Skip to main content
Version: near-api-js@1.1.0

Class: Account2FA

account_multisig.Account2FA

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

Hint

Use WalletConnection in the browser to redirect to NEAR Wallet for Account/key management using the BrowserLocalStorageKeyStore.

See

Hierarchy

Constructors

constructor

new Account2FA(connection, accountId, options)

Parameters

NameType
connectionConnection
accountIdstring
optionsany

Overrides

AccountMultisig.constructor

Defined in

account_multisig.ts:223

Properties

accountId

Readonly accountId: string

Inherited from

AccountMultisig.accountId

Defined in

account.ts:161


connection

Readonly connection: Connection

Inherited from

AccountMultisig.connection

Defined in

account.ts:160


getCode

getCode: getCodeFunction

Defined in

account_multisig.ts:218


helperUrl

helperUrl: string = 'https://helper.testnet.near.org'

Defined in

account_multisig.ts:221


onAddRequestResult

onAddRequestResult: (any: any) => any

Type declaration

(any): any

Parameters
NameType
anyany
Returns

any

Inherited from

AccountMultisig.onAddRequestResult

Defined in

account_multisig.ts:53


onConfirmResult

onConfirmResult: (any: any) => any

Type declaration

(any): any

Parameters
NameType
anyany
Returns

any

Defined in

account_multisig.ts:220


sendCode

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

Defined in

account_multisig.ts:217


storage

storage: any

Inherited from

AccountMultisig.storage

Defined in

account_multisig.ts:52


verifyCode

verifyCode: verifyCodeFunction

Defined in

account_multisig.ts:219

Methods

addKey

addKey(publicKey, contractId?, methodNames?, amount?): Promise<FinalExecutionOutcome>

See

https://docs.near.org/concepts/basics/accounts/access-keys

Todo

expand this API to support more options.

Parameters

NameTypeDescription
publicKeystring | PublicKeyA public key to be associated with the contract
contractId?stringNEAR account where the contract is deployed
methodNames?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.
amount?BNPayment in yoctoⓃ that is sent to the contract during this function call

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.addKey

Defined in

account.ts:443


checkMultisigCodeAndStateStatus

checkMultisigCodeAndStateStatus(contractBytes?): Promise<{ codeStatus: MultisigCodeStatus ; stateStatus: MultisigStateStatus }>

Parameters

NameType
contractBytes?Uint8Array

Returns

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

Inherited from

AccountMultisig.checkMultisigCodeAndStateStatus

Defined in

account_multisig.ts:121


createAccount

createAccount(newAccountId, publicKey, amount): Promise<FinalExecutionOutcome>

Parameters

NameTypeDescription
newAccountIdstringNEAR account name to be created
publicKeystring | PublicKeyA public key created from the masterAccount
amountBN-

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.createAccount

Defined in

account.ts:374


createAndDeployContract

createAndDeployContract(contractId, publicKey, data, amount): Promise<Account>

Create a new account and deploy a contract to it

Parameters

NameTypeDescription
contractIdstringNEAR account where the contract is deployed
publicKeystring | PublicKeyThe public key to add to the created contract account
dataUint8ArrayThe compiled contract code
amountBNof 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>

Inherited from

AccountMultisig.createAndDeployContract

Defined in

account.ts:349


deleteAccount

deleteAccount(beneficiaryId): Promise<FinalExecutionOutcome>

Parameters

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

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.deleteAccount

Defined in

account.ts:385


deleteAllRequests

deleteAllRequests(): Promise<void>

Returns

Promise<void>

Inherited from

AccountMultisig.deleteAllRequests

Defined in

account_multisig.ts:160


deleteKey

deleteKey(publicKey): Promise<FinalExecutionOutcome>

Parameters

NameTypeDescription
publicKeystring | PublicKeyThe public key to be deleted

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.deleteKey

Defined in

account.ts:466


deleteRequest

deleteRequest(request_id): Promise<FinalExecutionOutcome>

Parameters

NameType
request_idany

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.deleteRequest

Defined in

account_multisig.ts:153


deleteUnconfirmedRequests

deleteUnconfirmedRequests(): Promise<void>

Returns

Promise<void>

Inherited from

AccountMultisig.deleteUnconfirmedRequests

Defined in

account_multisig.ts:167


deployContract

deployContract(data): Promise<FinalExecutionOutcome>

Parameters

NameTypeDescription
dataUint8ArrayThe compiled contract code

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.deployContract

Defined in

account.ts:398


deployMultisig

deployMultisig(contractBytes): Promise<FinalExecutionOutcome>

Parameters

NameType
contractBytesUint8Array

Returns

Promise<FinalExecutionOutcome>

Defined in

account_multisig.ts:250


disable

disable(contractBytes?, cleanupContractBytes?): Promise<FinalExecutionOutcome>

This method converts LAKs back to FAKs, clears state and deploys an 'empty' contract (contractBytes param)

Parameters

NameTypeDescription
contractBytes?Uint8Arrayhttps://github.com/near/near-wallet/blob/master/packages/frontend/src/wasm/main.wasm?raw=true
cleanupContractBytes?Uint8Arrayhttps://github.com/near/core-contracts/blob/master/state-cleanup/res/state_cleanup.wasm?raw=true

Returns

Promise<FinalExecutionOutcome>

Defined in

account_multisig.ts:353


disableWithFAK

disableWithFAK(__namedParameters): Promise<FinalExecutionOutcome>

Parameters

NameType
__namedParametersObject
__namedParameters.cleanupContractBytes?Uint8Array
__namedParameters.contractBytesUint8Array

Returns

Promise<FinalExecutionOutcome>

Defined in

account_multisig.ts:288


findAccessKey

findAccessKey(receiverId, actions): Promise<{ accessKey: AccessKeyView ; publicKey: PublicKey }>

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

Todo

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

Parameters

NameTypeDescription
receiverIdstringcurrently unused (see todo)
actionsAction[]currently unused (see todo)

Returns

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

{ publicKey PublicKey; accessKey: AccessKeyView }

Inherited from

AccountMultisig.findAccessKey

Defined in

account.ts:297


functionCall

functionCall(__namedParameters): Promise<FinalExecutionOutcome>

Execute function call

Parameters

NameType
__namedParametersChangeFunctionCallOptions

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.functionCall

Defined in

account.ts:414


get2faDisableCleanupActions

get2faDisableCleanupActions(cleanupContractBytes): Promise<Action[]>

Parameters

NameType
cleanupContractBytesUint8Array

Returns

Promise<Action[]>

Defined in

account_multisig.ts:311


get2faDisableKeyConversionActions

get2faDisableKeyConversionActions(): Promise<Action[]>

Returns

Promise<Action[]>

Defined in

account_multisig.ts:329


get2faMethod

get2faMethod(): Promise<{ detail: any ; kind: any }>

Returns

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

Defined in

account_multisig.ts:437


getAccessKeys

getAccessKeys(): Promise<AccessKeyInfoView[]>

Get all access keys for the account

See

https://docs.near.org/api/rpc/access-keys#view-access-key-list

Returns

Promise<AccessKeyInfoView[]>

Inherited from

AccountMultisig.getAccessKeys

Defined in

account.ts:595


getAccountBalance

getAccountBalance(): Promise<AccountBalance>

Returns calculated account balance

Returns

Promise<AccountBalance>

Inherited from

AccountMultisig.getAccountBalance

Defined in

account.ts:629


getAccountDetails

getAccountDetails(): Promise<{ authorizedApps: AccountAuthorizedApp[] }>

Returns a list of authorized apps

Todo

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

Returns

Promise<{ authorizedApps: AccountAuthorizedApp[] }>

Inherited from

AccountMultisig.getAccountDetails

Defined in

account.ts:609


getActiveDelegatedStakeBalance

getActiveDelegatedStakeBalance(): Promise<ActiveDelegatedStakeBalance>

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>

Inherited from

AccountMultisig.getActiveDelegatedStakeBalance

Defined in

account.ts:653


getCodeDefault

getCodeDefault(): Promise<string>

Returns

Promise<string>

Defined in

account_multisig.ts:393


getRecoveryMethods

getRecoveryMethods(): Promise<{ accountId: string ; data: any }>

Returns

Promise<{ accountId: string ; data: any }>

Defined in

account_multisig.ts:429


getRequest

getRequest(): any

Returns

any

Inherited from

AccountMultisig.getRequest

Defined in

account_multisig.ts:195


getRequestIds

getRequestIds(): Promise<string[]>

Returns

Promise<string[]>

Inherited from

AccountMultisig.getRequestIds

Defined in

account_multisig.ts:189


postSignedJson

postSignedJson(path, body): Promise<any>

Parameters

NameType
pathany
bodyany

Returns

Promise<any>

Defined in

account_multisig.ts:456


promptAndVerify

promptAndVerify(): any

Returns

any

Defined in

account_multisig.ts:397


sendCodeDefault

sendCodeDefault(): Promise<any>

Returns

Promise<any>

Defined in

account_multisig.ts:381


sendMoney

sendMoney(receiverId, amount): Promise<FinalExecutionOutcome>

Parameters

NameTypeDescription
receiverIdstringNEAR account receiving Ⓝ
amountBNAmount to send in yoctoⓃ

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.sendMoney

Defined in

account.ts:363


setRequest

setRequest(data): any

Parameters

NameType
dataany

Returns

any

Inherited from

AccountMultisig.setRequest

Defined in

account_multisig.ts:202


signAndSendTransaction

Protected signAndSendTransaction(__namedParameters): Promise<FinalExecutionOutcome>

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

See

JsonRpcProvider.sendTransaction

Parameters

NameType
__namedParametersSignAndSendTransactionOptions

Returns

Promise<FinalExecutionOutcome>

Overrides

AccountMultisig.signAndSendTransaction

Defined in

account_multisig.ts:237


signAndSendTransactionWithAccount

signAndSendTransactionWithAccount(receiverId, actions): Promise<FinalExecutionOutcome>

Parameters

NameType
receiverIdstring
actionsAction[]

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.signAndSendTransactionWithAccount

Defined in

account_multisig.ts:61


signTransaction

Protected signTransaction(receiverId, actions): Promise<[Uint8Array, SignedTransaction]>

Create a signed transaction which can be broadcast to the network

See

JsonRpcProvider.sendTransaction

Parameters

NameTypeDescription
receiverIdstringNEAR account receiving the transaction
actionsAction[]list of actions to perform as part of the transaction

Returns

Promise<[Uint8Array, SignedTransaction]>

Inherited from

AccountMultisig.signTransaction

Defined in

account.ts:208


signatureFor

signatureFor(): Promise<{ blockNumber: string ; blockNumberSignature: string }>

Returns

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

Defined in

account_multisig.ts:447


stake

stake(publicKey, amount): Promise<FinalExecutionOutcome>

See

https://near-nodes.io/validator/staking-and-delegation

Parameters

NameTypeDescription
publicKeystring | PublicKeyThe public key for the account that's staking
amountBNThe account to stake in yoctoⓃ

Returns

Promise<FinalExecutionOutcome>

Inherited from

AccountMultisig.stake

Defined in

account.ts:479


state

state(): Promise<AccountView>

Returns basic NEAR account information via the view_account RPC query method

See

https://docs.near.org/api/rpc/contracts#view-account

Returns

Promise<AccountView>

Inherited from

AccountMultisig.state

Defined in

account.ts:172


verifyCodeDefault

verifyCodeDefault(securityCode): Promise<any>

Parameters

NameType
securityCodestring

Returns

Promise<any>

Defined in

account_multisig.ts:415


viewFunction

viewFunction(...restArgs): Promise<any>

Invoke a contract view function using the RPC API.

See

https://docs.near.org/api/rpc/contracts#call-a-contract-function

Parameters

NameType
...restArgsany

Returns

Promise<any>

Inherited from

AccountMultisig.viewFunction

Defined in

account.ts:512


viewFunctionV1

viewFunctionV1(contractId, methodName, args?, __namedParameters?): Promise<any>

Parameters

NameType
contractIdstring
methodNamestring
argsany
__namedParametersObject
__namedParameters.blockQuery?BlockReference
__namedParameters.jsContract?boolean
__namedParameters.parse?(response: Uint8Array) => any
__namedParameters.stringify?(input: any) => Buffer

Returns

Promise<any>

Inherited from

AccountMultisig.viewFunctionV1

Defined in

account.ts:524


viewFunctionV2

viewFunctionV2(__namedParameters): Promise<any>

Parameters

NameType
__namedParametersViewFunctionCallOptions

Returns

Promise<any>

Inherited from

AccountMultisig.viewFunctionV2

Defined in

account.ts:535


viewState

viewState(prefix, blockQuery?): Promise<{ key: Buffer ; value: Buffer }[]>

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.

See

https://docs.near.org/api/rpc/contracts#view-contract-state

Parameters

NameTypeDescription
prefixstring | Uint8Arrayallows to filter which keys should be returned. Empty prefix means all keys. String prefix is utf-8 encoded.
blockQueryBlockReferencespecifies which block to query state at. By default returns last "optimistic" block (i.e. not necessarily finalized).

Returns

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

Inherited from

AccountMultisig.viewState

Defined in

account.ts:577