import { PublicKey } from '@meer-js/crypto'; import { Action, SignedDelegate, SignedTransaction } from '@meer-js/transactions'; import type { FinalExecutionOutcome, AccountView, AccessKeyView, AccessKeyInfoView, BlockReference } from '@meer-js/types'; import { Connection } from './connection.js'; import { ChangeFunctionCallOptions, IntoConnection, ViewFunctionCallOptions } from './interface.js'; export interface AccountBalance { total: string; stateStaked: string; staked: string; available: string; } export interface AccountAuthorizedApp { contractId: string; amount: string; publicKey: string; } /** * Options used to initiate sining and sending transactions */ export interface SignAndSendTransactionOptions { receiverId: string; actions: Action[]; /** * Metadata to send the NEAR Wallet if using it to sign transactions. * @see RequestSignTransactionsOptions */ walletMeta?: string; /** * Callback url to send the NEAR Wallet if using it to sign transactions. * @see RequestSignTransactionsOptions */ walletCallbackUrl?: string; returnError?: boolean; } interface StakedBalance { validatorId: string; amount?: string; error?: string; } interface ActiveDelegatedStakeBalance { stakedValidators: StakedBalance[]; failedValidators: StakedBalance[]; total: bigint | string; } interface SignedDelegateOptions { actions: Action[]; blockHeightTtl: number; receiverId: string; } /** * This class provides common account related RPC calls including signing transactions with a {@link "@near-js/crypto".key_pair.KeyPair | KeyPair}. */ export declare class Account implements IntoConnection { readonly connection: Connection; readonly accountId: string; constructor(connection: Connection, accountId: string); getConnection(): Connection; /** * Returns basic NEAR account information via the `view_account` RPC query method * @see [https://docs.near.org/api/rpc/contracts#view-account](https://docs.near.org/api/rpc/contracts#view-account) */ state(): Promise; /** * Create a signed transaction which can be broadcast to the network * @param receiverId NEAR account receiving the transaction * @param actions list of actions to perform as part of the transaction * @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider.sendTransaction | JsonRpcProvider.sendTransaction} */ protected signTransaction(receiverId: string, actions: Action[]): Promise<[Uint8Array, SignedTransaction]>; /** * Sign a transaction to perform a list of actions and broadcast it using the RPC API. * @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider | JsonRpcProvider } * * @param options The options for signing and sending the transaction. * @param options.receiverId The NEAR account ID of the transaction receiver. * @param options.actions The list of actions to be performed in the transaction. * @param options.returnError Whether to return an error if the transaction fails. * @returns {Promise} A promise that resolves to the final execution outcome of the transaction. */ signAndSendTransaction({ receiverId, actions, returnError }: SignAndSendTransactionOptions): Promise; /** @hidden */ accessKeyByPublicKeyCache: { [key: string]: AccessKeyView; }; /** * Finds the {@link AccessKeyView} associated with the accounts {@link PublicKey} stored in the {@link "@near-js/keystores".keystore.KeyStore | Keystore}. * * @todo Find matching access key based on transaction (i.e. receiverId and actions) * * @param receiverId currently unused (see todo) * @param actions currently unused (see todo) * @returns `{ publicKey PublicKey; accessKey: AccessKeyView }` */ findAccessKey(receiverId: string, actions: Action[]): Promise<{ publicKey: PublicKey; accessKey: AccessKeyView; }>; /** * Create a new account and deploy a contract to it * * @param contractId NEAR account where the contract is deployed * @param publicKey The public key to add to the created contract account * @param data The compiled contract code * @param amount of NEAR to transfer to the created contract account. Transfer enough to pay for storage https://docs.near.org/docs/concepts/storage-staking */ createAndDeployContract(contractId: string, publicKey: string | PublicKey, data: Uint8Array, amount: bigint): Promise; /** * @param receiverId NEAR account receiving Ⓝ * @param amount Amount to send in yoctoⓃ */ sendMoney(receiverId: string, amount: bigint): Promise; /** * @param newAccountId NEAR account name to be created * @param publicKey A public key created from the masterAccount */ createAccount(newAccountId: string, publicKey: string | PublicKey, amount: bigint): Promise; /** * @param beneficiaryId The NEAR account that will receive the remaining Ⓝ balance from the account being deleted */ deleteAccount(beneficiaryId: string): Promise; /** * @param data The compiled contract code */ deployContract(data: Uint8Array): Promise; /** @hidden */ private encodeJSContractArgs; /** * Execute a function call. * @param options The options for the function call. * @param options.contractId The NEAR account ID of the smart contract. * @param options.methodName The name of the method to be called on the smart contract. * @param options.args The arguments to be passed to the method. * @param options.gas The maximum amount of gas to be used for the function call. * @param options.attachedDeposit The amount of NEAR tokens to be attached to the function call. * @param options.walletMeta Metadata for wallet integration. * @param options.walletCallbackUrl The callback URL for wallet integration. * @param options.stringify A function to convert input arguments into bytes array * @param options.jsContract Whether the contract is from JS SDK, automatically encodes args from JS SDK to binary. * @returns {Promise} A promise that resolves to the final execution outcome of the function call. */ functionCall({ contractId, methodName, args, gas, attachedDeposit, walletMeta, walletCallbackUrl, stringify, jsContract }: ChangeFunctionCallOptions): Promise; /** * @see [https://docs.near.org/concepts/basics/accounts/access-keys](https://docs.near.org/concepts/basics/accounts/access-keys) * @todo expand this API to support more options. * @param publicKey A public key to be associated with the contract * @param contractId NEAR account where the contract is deployed * @param methodNames 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. * @param amount Payment in yoctoⓃ that is sent to the contract during this function call */ addKey(publicKey: string | PublicKey, contractId?: string, methodNames?: string | string[], amount?: bigint): Promise; /** * @param publicKey The public key to be deleted * @returns {Promise} */ deleteKey(publicKey: string | PublicKey): Promise; /** * @see [https://near-nodes.io/validator/staking-and-delegation](https://near-nodes.io/validator/staking-and-delegation) * * @param publicKey The public key for the account that's staking * @param amount The account to stake in yoctoⓃ */ stake(publicKey: string | PublicKey, amount: bigint): Promise; /** * Compose and sign a SignedDelegate action to be executed in a transaction on behalf of this Account instance * * @param options Options for the transaction. * @param options.actions Actions to be included in the meta transaction * @param options.blockHeightTtl Number of blocks past the current block height for which the SignedDelegate action may be included in a meta transaction * @param options.receiverId Receiver account of the meta transaction */ signedDelegate({ actions, blockHeightTtl, receiverId, }: SignedDelegateOptions): Promise; /** @hidden */ private validateArgs; /** * Invoke a contract view function using the RPC API. * @see [https://docs.near.org/api/rpc/contracts#call-a-contract-function](https://docs.near.org/api/rpc/contracts#call-a-contract-function) * * @param options Function call options. * @param options.contractId NEAR account where the contract is deployed * @param options.methodName The view-only method (no state mutations) name on the contract as it is written in the contract code * @param options.args Any arguments to the view contract method, wrapped in JSON * @param options.parse Parse the result of the call. Receives a Buffer (bytes array) and converts it to any object. By default result will be treated as json. * @param options.stringify Convert input arguments into a bytes array. By default the input is treated as a JSON. * @param options.jsContract Is contract from JS SDK, automatically encodes args from JS SDK to binary. * @param options.blockQuery specifies which block to query state at. By default returns last "optimistic" block (i.e. not necessarily finalized). * @returns {Promise} */ viewFunction(options: ViewFunctionCallOptions): Promise; /** * 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](https://docs.near.org/api/rpc/contracts#view-contract-state) * * @param prefix allows to filter which keys should be returned. Empty prefix means all keys. String prefix is utf-8 encoded. * @param blockQuery specifies which block to query state at. By default returns last "optimistic" block (i.e. not necessarily finalized). */ viewState(prefix: string | Uint8Array, blockQuery?: BlockReference): Promise>; /** * Get all access keys for the account * @see [https://docs.near.org/api/rpc/access-keys#view-access-key-list](https://docs.near.org/api/rpc/access-keys#view-access-key-list) */ getAccessKeys(): Promise; /** * Returns a list of authorized apps * @todo update the response value to return all the different keys, not just app keys. */ getAccountDetails(): Promise<{ authorizedApps: AccountAuthorizedApp[]; }>; /** * Returns calculated account balance */ getAccountBalance(): Promise; /** * 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} */ getActiveDelegatedStakeBalance(): Promise; } export {}; //# sourceMappingURL=account.d.ts.map