How to use the @zilliqa-js/core.RPCMethod.GetSmartContractSubState function in @zilliqa-js/core

To help you get started, we’ve selected a few @zilliqa-js/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-blockchain / src / chain.ts View on Github external
getSmartContractSubState(
    addr: string,
    variableName: string,
    indices?: string[],
  ): Promise> {
    const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
    if (!variableName) {
      throw new Error('Variable name required');
    }

    return this.provider.send(
      RPCMethod.GetSmartContractSubState,
      address.replace('0x', '').toLowerCase(),
      variableName,
      indices === undefined ? [] : indices,
    );
  }
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-contract / src / contract.ts View on Github external
async getSubState(variableName: string, indices?: string[]): Promise {
    if (this.status !== ContractStatus.Deployed) {
      return Promise.resolve([]);
    }

    if (!this.address) {
      throw new Error('Cannot get state of uninitialised contract');
    }

    if (!variableName) {
      throw new Error('Variable name required');
    }

    const response = await this.provider.send(
      RPCMethod.GetSmartContractSubState,
      this.address.replace('0x', '').toLowerCase(),
      variableName,
      indices === undefined ? [] : indices,
    );

    return response.result;
  }