Hierarchy

  • Account

Implements

Constructors

Properties

_accountId: string

Accessors

Methods

  • Create a Transaction that can be used to build actions like transfer, createAccount, etc. Then once built can be signed and transmitted. E.g.

    const result = await account.batch(bob).transfer(NEAR.parse("1N")).transact();
    

    Parameters

    • receiver: string | NearAccount

      account that the transaction is addressed to.

    Returns Transaction

  • Convenient wrapper around lower-level callRaw that returns only successful result of call, or throws error encountered during call. Example:

    await call('lol.testnet', 'set_status', { message: 'hello' }, new BN(30 * 10**12), '0')
    

    Type Parameters

    • T

    Parameters

    • contractId: string | NearAccount
    • methodName: string
    • args: Uint8Array | Record<string, unknown>
    • __namedParameters: {
          attachedDeposit?: string | new BN;
          gas?: string | new BN;
          signWithKey?: KeyPair;
      } = {}
      • Optional attachedDeposit?: string | new BN
      • Optional gas?: string | new BN
      • Optional signWithKey?: KeyPair

    Returns Promise<T>

    any parsed return value, or throws with an error if call failed

  • Call a NEAR contract and return full results with raw receipts, etc. Example:

    await callRaw('lol.testnet', 'set_status', { message: 'hello' }, {gas: new BN(30 * 10**12), attachedDeposit: new BN(10**24)})

    //`gas` and `initialBalance` as strings can be either numbers, e.g. `1_000_000` or have units, `30 Tgas`

    await callRaw('lol.testnet', 'set_status', { message: 'hello' }, {gas:"10 Tgas", attachedDeposit: "1 N"})

    Parameters

    • contractId: string | NearAccount
    • methodName: string
    • args: Uint8Array | Record<string, unknown>
    • __namedParameters: {
          attachedDeposit?: string | new BN;
          gas?: string | new BN;
          signWithKey?: KeyPair;
      } = {}
      • Optional attachedDeposit?: string | new BN
      • Optional gas?: string | new BN
      • Optional signWithKey?: KeyPair

    Returns Promise<TransactionResult>

    Promise

  • Create a subaccount from this account

    Parameters

    • accountId: string

      full accountId with current account name as suffix.

    • __namedParameters: {
          initialBalance?: string;
          isSubAccount?: boolean;
          keyPair?: KeyPair;
      } = {}

      keyPair is key to be added to keystore, otherwise random one will be added. initialBalance how much yoctoNear to transfer to new account.

      • Optional initialBalance?: string
      • Optional isSubAccount?: boolean
      • Optional keyPair?: KeyPair

    Returns Promise<NearAccount>

  • Create a subaccount from this account

    Parameters

    • accountId: string

      prefix of accountId with current account name as suffix.

    • __namedParameters: {
          initialBalance?: string;
          isSubAccount?: boolean;
          keyPair?: KeyPair;
      } = {}

      keyPair is key to be added to keystore, otherwise random one will be added. initialBalance how much yoctoNear to transfer to new account.

      • Optional initialBalance?: string
      • Optional isSubAccount?: boolean
      • Optional keyPair?: KeyPair

    Returns Promise<NearAccount>

  • Creates an account for a contract and then deploys a Wasm binary to it. If method arguments are provided a function call to method will be added to the transaction so that the contract can be initialized in the same step.

    Parameters

    • wasm: string | Uint8Array | Buffer | URL

      path or data of contract binary

    • __namedParameters: {
          args?: Uint8Array | Record<string, unknown>;
          attachedDeposit?: string | new BN;
          gas?: string | new BN;
          initialBalance?: string | new BN;
          isSubAccount?: boolean;
          keyPair?: KeyPair;
          method?: string;
      } = {}

      If any method is passed it will be added to the transaction so that contract will be initialized gas and initialBalance as strings can be either numbers, e.g. 1_000_000 or have units, 30 Tgas

      • Optional args?: Uint8Array | Record<string, unknown>
      • Optional attachedDeposit?: string | new BN
      • Optional gas?: string | new BN
      • Optional initialBalance?: string | new BN
      • Optional isSubAccount?: boolean
      • Optional keyPair?: KeyPair
      • Optional method?: string

    Returns Promise<NearAccount>

  • Create an account, copying Wasm bytes and contract name from a given testnetContract or mainnetContract.

    This makes use of Sandbox's patch state feature, and so only works in Sandbox mode.

    You can include withData: true to copy account data as well, but this is currently limited by the default RPC limit of 50kB. You could set up your own RPC server to get around this limit (using your own RPC endpoint will be easier soon).

    Parameters

    • __namedParameters: {
          blockId?: string | number;
          initialBalance?: string;
          keyPair?: KeyPair;
          mainnetContract?: string;
          testnetContract?: string;
          withData?: boolean;
      }
      • Optional blockId?: string | number
      • Optional initialBalance?: string
      • Optional keyPair?: KeyPair
      • Optional mainnetContract?: string
      • Optional testnetContract?: string
      • Optional withData?: boolean

    Returns Promise<NearAccount>

  • Patch state data of given key and value to sandbox

    Parameters

    • key: string

      key to update in storage

    • value_: any

      Data to be serialized to JSON by default

    • Optional borshSchema: any

      If passed will be used to encode the data

    Returns Promise<Empty>

  • Update contract data of account.

    Uses patchStateRecords to update the account without a transaction. Only works with network: 'sandbox'.

    Parameters

    • key: string | Buffer

      Base64 encoded string or Buffer to be encoded as Base64

    • value: string | Buffer

      Base64 encoded string or Buffer to be encoded as Base64

    Returns Promise<Empty>

  • Get the parsed result returned by view method

    Type Parameters

    • T

    Parameters

    • method: string

      contract method

    • args: Args = {}

      args to pass to method if required

    Returns Promise<T>

Generated using TypeDoc