How to use the @zilliqa-js/crypto.fromBech32Address function in @zilliqa-js/crypto

To help you get started, we’ve selected a few @zilliqa-js/crypto 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
getBalance(addr: string): Promise> {
    const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
    return this.provider.send(
      RPCMethod.GetBalance,
      address.replace('0x', '').toLowerCase(),
    );
  }
github Zilliqa / nucleus-wallet / src / components / account-info / index.tsx View on Github external
const AccountInfo = ({ address, getBalance }) => {
  const bech32Address = toBech32Address(address);
  const { data, error, isPending, run } = useAsyncFn({ promiseFn: getBalance });
  return (
    <div>
      <div>
        <h5>
          <b>{'Account Info'}</b>
        </h5>
        <div>
          <div>
            {bech32Address ? (
              
            ) : null}
          </div>
          <div>
            <b>{'Address'}</b>
            <p>
              <a rel="noopener noreferrer" href="{getAddressExplorerURL(bech32Address)}">{`${bech32Address}`}</a>{' '}
              
              <br>
              <small>{`(ByStr20: ${address})`}</small>
            </p>
            <b></b></div></div></div></div>
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-blockchain / src / chain.ts View on Github external
getSmartContracts(
    addr: string,
  ): Promise, string&gt;&gt; {
    const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
    return this.provider.send(
      RPCMethod.GetSmartContracts,
      address.replace('0x', '').toLowerCase(),
    );
  }
github zilpay / zil-pay / src / views / Import.vue View on Github external
async ledgerGetAddress() {
      this.spiner();
      const hwIndex = this.ladgerIndex;
      const hwType = 'ledger';

      try {
        if (isNaN(hwIndex)) {
          throw new Error('index must be number');
        }
        let { pubAddr, publicKey } = await ledgerControll.getAddresses(
          hwIndex
        );

        pubAddr = fromBech32Address(pubAddr);
        await this.importByHw({
          pubAddr, hwIndex, hwType, publicKey
        });
        this.spiner();
        this.$router.push({ name: 'Home' });
        return null;
      } catch(err) {
        this.ledgerErr = err.message;
      }
      this.spiner();
    }
  }
github Zilliqa / nucleus-wallet / src / redux / zil / sagas.ts View on Github external
yield delay(500);
  try {
    const { payload } = action;
    const { toAddress, amount } = payload;

    const zilState = yield select(getZilState);
    const { zilliqa, provider, privateKey, address, publicKey } = zilState;

    const response = yield zilliqa.blockchain.getMinimumGasPrice();
    const minGasPriceInQa: string = response.result;

    const nonceResponse = yield zilliqa.blockchain.getBalance(address);
    const nonceData = nonceResponse.result.nonce || { nonce: 0 };
    const nonce: number = nonceData.nonce + 1;

    const toAddr = fromBech32Address(toAddress);
    const wallet = zilliqa.wallet;
    wallet.addByPrivateKey(privateKey);

    const tx = new Transaction(
      {
        version: VERSION,
        toAddr,
        amount: units.toQa(amount, units.Units.Zil),
        gasPrice: new BN(minGasPriceInQa),
        gasLimit: Long.fromNumber(1),
        pubKey: publicKey,
        nonce
      },
      provider
    );
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-blockchain / src / chain.ts View on Github external
getSmartContractCode(
    addr: string,
  ): Promise&gt; {
    const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
    return this.provider.send(
      RPCMethod.GetSmartContractCode,
      address.replace('0x', '').toLowerCase(),
    );
  }
github zilpay / zil-pay / extension / controllers / services / blockchain / zilliqa.js View on Github external
'toAddr'
    ].forEach(key => {
      if (!payload.hasOwnProperty(key)) {
        throw new Error(
          errorsCode.WrongRequiredparam + key
        );
      }
    });

    const storage = new BrowserStorage();
    let forConfirm = await storage.get(fields.CONFIRM_TX);

    if (validation.isBase58(payload.toAddr)) {
      payload.toAddr = decodeBase58(payload.toAddr);
    } else if (validation.isBech32(payload.toAddr)) {
      payload.toAddr = fromBech32Address(payload.toAddr);
    }

    payload.toAddr = toChecksumAddress(payload.toAddr);

    try {
      forConfirm = forConfirm[fields.CONFIRM_TX];
      forConfirm.push(payload);
    } catch(err) {
      forConfirm = [payload];
    }

    await storage.set(new BuildObject(fields.CONFIRM_TX, forConfirm));
    this.notificationsCounter(forConfirm);
  }
github zilpay / zil-pay / packages / background / services / blockchain / zilliqa.js View on Github external
for (let index = 0; index &lt; neededParams.length; index++) {
      const param = neededParams[index]

      if (!(param in payload)) {
        throw new Error(
          errorsCode.WrongRequiredparam + param
        )
      }
    }

    const storage = new BrowserStorage()
    let forConfirm = await storage.get(FIELDS.CONFIRM_TX)

    if (validation.isBech32(payload.toAddr)) {
      payload.toAddr = fromBech32Address(payload.toAddr)
    }

    payload.toAddr = toChecksumAddress(payload.toAddr)

    try {
      forConfirm.push(payload)
    } catch (err) {
      forConfirm = [payload]
    }

    await storage.set(
      new BuildObject(FIELDS.CONFIRM_TX, forConfirm)
    )

    this.notificationsCounter(forConfirm)
  }
github Zilliqa / nucleus-wallet / src / contexts / zil-context / index.tsx View on Github external
public faucet = async ({ args, signal }): Promise =&gt; {
    const { token, toAddress } = args;
    const address = fromBech32Address(toAddress);
    const body = JSON.stringify({ address, token });
    const res = await fetch(`${getHost(window.location.hostname)}/faucet/run`, {
      signal,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body
    });
    if (!res.ok) throw new Error('Failed to run faucet');
    const data = await res.json();
    return data ? data.txId : undefined;
  };
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-blockchain / src / chain.ts View on Github external
getSmartContractState(addr: string): Promise&gt; {
    const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
    return this.provider.send(
      RPCMethod.GetSmartContractState,
      address.replace('0x', '').toLowerCase(),
    );
  }