跳到主要内容
版本:near-api-js@1.1.0

Class: ConnectedWalletAccount

walletAccount.ConnectedWalletAccount

Account implementation which redirects to wallet using WalletConnection when no local key is available.

Hierarchy​

Constructors​

constructor​

new ConnectedWalletAccount(walletConnection, connection, accountId)

Parameters​

NameType
walletConnectionWalletConnection
connectionConnection
accountIdstring

Overrides​

Account.constructor

Defined in​

wallet-account.ts:287

Properties​

accountId​

Readonly accountId: string

Inherited from​

Account.accountId

Defined in​

account.ts:161


connection​

Readonly connection: Connection

Inherited from​

Account.connection

Defined in​

account.ts:160


walletConnection​

walletConnection: WalletConnection

Defined in​

wallet-account.ts:285

Methods​

accessKeyForTransaction​

accessKeyForTransaction(receiverId, actions, localKey?): Promise<any>

Helper function returning the access key (if it exists) to the receiver that grants the designated permission

Parameters​

NameTypeDescription
receiverIdstringThe NEAR account seeking the access key for a transaction
actionsAction[]The action(s) sought to gain access to
localKey?PublicKeyA local public key provided to check for access

Returns​

Promise<any>

Defined in​

wallet-account.ts:383


accessKeyMatchesTransaction​

accessKeyMatchesTransaction(accessKey, receiverId, actions): Promise<boolean>

Check if given access key allows the function call or method attempted in transaction

Parameters​

NameTypeDescription
accessKeyanyArray of {access_key: AccessKey, public_key: PublicKey} items
receiverIdstringThe NEAR account attempting to have access
actionsAction[]The action(s) needed to be checked for access

Returns​

Promise<boolean>

Defined in​

wallet-account.ts:346


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​

Account.addKey

Defined in​

account.ts:443


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​

Account.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​

Account.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​

Account.deleteAccount

Defined in​

account.ts:385


deleteKey​

deleteKey(publicKey): Promise<FinalExecutionOutcome>

Parameters​

NameTypeDescription
publicKeystring | PublicKeyThe public key to be deleted

Returns​

Promise<FinalExecutionOutcome>

Inherited from​

Account.deleteKey

Defined in​

account.ts:466


deployContract​

deployContract(data): Promise<FinalExecutionOutcome>

Parameters​

NameTypeDescription
dataUint8ArrayThe compiled contract code

Returns​

Promise<FinalExecutionOutcome>

Inherited from​

Account.deployContract

Defined in​

account.ts:398


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​

Account.findAccessKey

Defined in​

account.ts:297


functionCall​

functionCall(__namedParameters): Promise<FinalExecutionOutcome>

Execute function call

Parameters​

NameType
__namedParametersChangeFunctionCallOptions

Returns​

Promise<FinalExecutionOutcome>

Inherited from​

Account.functionCall

Defined in​

account.ts:414


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​

Account.getAccessKeys

Defined in​

account.ts:595


getAccountBalance​

getAccountBalance(): Promise<AccountBalance>

Returns calculated account balance

Returns​

Promise<AccountBalance>

Inherited from​

Account.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​

Account.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​

Account.getActiveDelegatedStakeBalance

Defined in​

account.ts:653


sendMoney​

sendMoney(receiverId, amount): Promise<FinalExecutionOutcome>

Parameters​

NameTypeDescription
receiverIdstringNEAR account receiving Ⓝ
amountBNAmount to send in yoctoⓃ

Returns​

Promise<FinalExecutionOutcome>

Inherited from​

Account.sendMoney

Defined in​

account.ts:363


signAndSendTransaction​

Protected signAndSendTransaction(__namedParameters): Promise<FinalExecutionOutcome>

Sign a transaction by redirecting to the NEAR Wallet

See

requestSignTransactions

Parameters​

NameType
__namedParametersSignAndSendTransactionOptions

Returns​

Promise<FinalExecutionOutcome>

Overrides​

Account.signAndSendTransaction

Defined in​

wallet-account.ts:298


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​

Account.signTransaction

Defined in​

account.ts:208


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​

Account.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​

Account.state

Defined in​

account.ts:172


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​

Account.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​

Account.viewFunctionV1

Defined in​

account.ts:524


viewFunctionV2​

viewFunctionV2(__namedParameters): Promise<any>

Parameters​

NameType
__namedParametersViewFunctionCallOptions

Returns​

Promise<any>

Inherited from​

Account.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​

Account.viewState

Defined in​

account.ts:577