Class: Account
account.Account
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
Account
Constructors
constructor
new Account(connection
, accountId
)
Parameters
Name | Type |
---|---|
connection | Connection |
accountId | string |
Defined in
Properties
accountId
Readonly
accountId: string
Defined in
connection
Readonly
connection: Connection
Defined in
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
Name | Type | Description |
---|---|---|
publicKey | string | PublicKey | A public key to be associated with the contract |
contractId? | string | NEAR 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? | BN | Payment in yoctoⓃ that is sent to the contract during this function call |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
createAccount
createAccount(newAccountId
, publicKey
, amount
): Promise
<FinalExecutionOutcome
>
Parameters
Name | Type | Description |
---|---|---|
newAccountId | string | NEAR account name to be created |
publicKey | string | PublicKey | A public key created from the masterAccount |
amount | BN | - |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
createAndDeployContract
createAndDeployContract(contractId
, publicKey
, data
, amount
): Promise
<Account
>
Create a new account and deploy a contract to it
Parameters
Name | Type | Description |
---|---|---|
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 | BN | 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
>
Defined in
deleteAccount
deleteAccount(beneficiaryId
): Promise
<FinalExecutionOutcome
>
Parameters
Name | Type | Description |
---|---|---|
beneficiaryId | string | The NEAR account that will receive the remaining Ⓝ balance from the account being deleted |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
deleteKey
deleteKey(publicKey
): Promise
<FinalExecutionOutcome
>
Parameters
Name | Type | Description |
---|---|---|
publicKey | string | PublicKey | The public key to be deleted |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
deployContract
deployContract(data
): Promise
<FinalExecutionOutcome
>
Parameters
Name | Type | Description |
---|---|---|
data | Uint8Array | The compiled contract code |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
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
Name | Type | Description |
---|---|---|
receiverId | string | currently unused (see todo) |
actions | Action [] | currently unused (see todo) |
Returns
Promise
<{ accessKey
: AccessKeyView
; publicKey
: PublicKey
}>
{ publicKey PublicKey; accessKey: AccessKeyView }
Defined in
functionCall
functionCall(__namedParameters
): Promise
<FinalExecutionOutcome
>
Execute function call
Parameters
Name | Type |
---|---|
__namedParameters | ChangeFunctionCallOptions |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
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
[]>
Defined in
getAccountBalance
getAccountBalance(): Promise
<AccountBalance
>
Returns calculated account balance
Returns
Promise
<AccountBalance
>
Defined in
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
[] }>
Defined in
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
>
Defined in
sendMoney
sendMoney(receiverId
, amount
): Promise
<FinalExecutionOutcome
>
Parameters
Name | Type | Description |
---|---|---|
receiverId | string | NEAR account receiving Ⓝ |
amount | BN | Amount to send in yoctoⓃ |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
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
Name | Type |
---|---|
__namedParameters | SignAndSendTransactionOptions |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
signTransaction
Protected
signTransaction(receiverId
, actions
): Promise
<[Uint8Array
, SignedTransaction
]>
Create a signed transaction which can be broadcast to the network
See
JsonRpcProvider.sendTransaction
Parameters
Name | Type | Description |
---|---|---|
receiverId | string | NEAR account receiving the transaction |
actions | Action [] | list of actions to perform as part of the transaction |
Returns
Promise
<[Uint8Array
, SignedTransaction
]>
Defined in
stake
stake(publicKey
, amount
): Promise
<FinalExecutionOutcome
>
See
https://near-nodes.io/validator/staking-and-delegation
Parameters
Name | Type | Description |
---|---|---|
publicKey | string | PublicKey | The public key for the account that's staking |
amount | BN | The account to stake in yoctoⓃ |
Returns
Promise
<FinalExecutionOutcome
>
Defined in
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
>
Defined in
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
Name | Type |
---|---|
...restArgs | any |
Returns
Promise
<any
>
Defined in
viewFunctionV1
viewFunctionV1(contractId
, methodName
, args?
, __namedParameters?
): Promise
<any
>
Parameters
Name | Type |
---|---|
contractId | string |
methodName | string |
args | any |
__namedParameters | Object |
__namedParameters.blockQuery? | BlockReference |
__namedParameters.jsContract? | boolean |
__namedParameters.parse? | (response : Uint8Array ) => any |
__namedParameters.stringify? | (input : any ) => Buffer |
Returns
Promise
<any
>
Defined in
viewFunctionV2
viewFunctionV2(__namedParameters
): Promise
<any
>
Parameters
Name | Type |
---|---|
__namedParameters | ViewFunctionCallOptions |
Returns
Promise
<any
>
Defined in
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
Name | Type | Description |
---|---|---|
prefix | string | Uint8Array | allows to filter which keys should be returned. Empty prefix means all keys. String prefix is utf-8 encoded. |
blockQuery | 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
}[]>