How to use ethjs-unit - 10 common examples

To help you get started, we’ve selected a few ethjs-unit 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 MyEtherWallet / MyEtherWallet / src / dapps / Aave / components / ConfirmationModal / ConfirmationModal.vue View on Github external
takeAction() {
      const param = {
        address: this.token.address,
        amount: new BigNumber(unit.toWei(this.amount, 'ether')).toString(),
      }

      if (!this.activeDepositTab) {
        param['rate'] = this.selectStable ? 0 : 1;
      }

      param['referral'] = 0;// do  i need to put referral code? is 0 mean no referral?

      this.$emit('takeAction', param); 
    },
    convertToUSD(balance) {
github klaytn / caver-js / packages / caver-utils / src / index.js View on Github external
const toPeb = function(number, unit) {
    // kaly unit to eth unit
    unit = getKlayUnitValue(unit)
    unit = unitKlayToEthMap[unit]

    unit = getUnitValue(unit)

    if (!utils.isBN(number) && !_.isString(number)) {
        number = tryNumberToString(number)
    }

    return utils.isBN(number) ? ethjsUnit.toWei(number, unit) : ethjsUnit.toWei(number, unit).toString(10)
}
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SendOfflineContainer / components / GenerateTx / GenerateTx.vue View on Github external
async generateTx() {
      const raw = {
        from: this.wallet.getAddressString(),
        gas: this.localGas,
        value:
          this.selectedCoinType.symbol !== this.network.type.name
            ? 0
            : unit.toWei(this.toAmt, 'ether'),
        data: this.toData,
        nonce: this.locNonce,
        gasPrice: unit.toWei(this.gasPrice, 'gwei'),
        to:
          this.selectedCoinType.symbol !== this.network.type.name
            ? this.selectedCoinType.address
            : this.address,
        chainId: this.network.type.chainID,
        generateOnly: true
      };
      this.raw = raw;
      this.wallet
        .signTransaction(this.raw)
        .then(signed => {
          this.signed = JSON.stringify(signed);
          this.$emit('createdRawTx', this.signed);
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / components / GenerateTx / GenerateTx.vue View on Github external
next() {
      const raw = {
        from: this.wallet.getAddressString(),
        gas: this.localGas,
        value: unit.toWei(this.toAmt, 'ether'),
        data: this.toData,
        nonce: this.locNonce,
        gasPrice: Number(unit.toWei(this.gasPrice, 'gwei')),
        to:
          this.resolvedAddress !== ''
            ? this.resolvedAddress
            : this.address !== ''
            ? this.address
            : '',
        chainId: this.network.type.chainID || 1
      };
      this.web3.eth.signTransaction(raw).then(signedTx => {
        this.$emit('createdRawTx', signedTx.rawTransaction);

        this.raw = raw;
        this.signed = signedTx.rawTransaction;
        this.$refs.signedTxModal.$refs.signedTx.show();
        window.scrollTo(0, 0);
      });
github invisible-college / democracy / packages / depart / departDS.js View on Github external
}), async ({ deployed, minedTx, deployerAddress }) => {
  const ds = await deployed( 'DifferentSender', { force: true } )
 
  //const instance = await relink.getInstance() 
  const txReceipt = await minedTx( ds.send, [deployerAddress], {value: toWei('0.1', 'ether')} )
  const owner      = toChecksumAddress((await ds.owner())['0'])
  const lastSender = toChecksumAddress((await ds.lastSender())['0'])
  const lastPayer  = toChecksumAddress((await ds.lastPayer())['0'])
  const lastValue  = (await ds.lastValue())['0']
  assert.equal( owner      , deployerAddress )
  assert.equal( lastSender , deployerAddress )
  assert.equal( lastPayer  , deployerAddress )
  assert.equal( lastValue.toString()  , toWei('0.1', 'ether').toString() )
 
  return 22
})
github MyEtherWallet / MyEtherWallet / src / dapps / ScheduleTransaction / containers / ScheduleView.vue View on Github external
estimatedMaximumExecutionGasPrice() {
      if (
        !this.isValidFutureGasPrice ||
        !this.isValidFutureGasLimit ||
        !this.isValidTimeBounty
      )
        return 0;

      const estimated = Util.estimateMaximumExecutionGasPrice(
        new BigNumber(unit.toWei(this.timeBounty, 'ether')),
        new BigNumber(unit.toWei(this.futureGasPrice, 'gwei')),
        new BigNumber(this.futureGasLimit)
      );

      return Math.round(unit.fromWei(estimated.toString(), 'gwei'));
    },
    now() {
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SendOfflineContainer / SendOfflineContainer.vue View on Github external
async generateTx() {
      const symbol = this.network.type.currencyName;
      const isToken = this.selectedCoinType.symbol !== symbol;
      const amtWei = unit.toWei(this.toAmt, 'ether');
      const raw = {
        nonce: Misc.sanitizeHex(new BigNumber(this.localNonce).toString(16)),
        gasLimit: Misc.sanitizeHex(new BigNumber(this.gasLimit).toString(16)),
        gasPrice: Misc.sanitizeHex(
          new BigNumber(unit.toWei(this.localGasPrice, 'gwei')).toString(16)
        ),
        to: isToken
          ? this.selectedCoinType.address
          : this.address.toLowerCase().trim(),
        value: isToken ? 0 : amtWei,
        data: this.toData,
        chainId: this.network.type.chainID
      };
      this.raw = raw;
      const signed = await this.wallet.signTransaction(this.raw);
      this.signed = JSON.stringify(signed);
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SendCurrencyContainer / SendCurrencyContainer.vue View on Github external
);
      this.data = isEth
        ? this.data
        : contract.methods
            .transfer(this.address, unit.toWei(this.amount, 'ether'))
            .encodeABI();

      this.raw = {
        from: this.$store.state.wallet.getAddressString(),
        gas: this.gasLimit,
        nonce: this.nonce,
        gasPrice: Number(unit.toWei(this.$store.state.gasPrice, 'gwei')),
        value: isEth
          ? this.amount === ''
            ? 0
            : unit.toWei(this.amount, 'ether')
          : 0,
        to: isEth ? this.address : this.selectedCurrency.addr,
        data: this.data,
        chainId: this.$store.state.network.type.chainID || 1
      };

      if (this.address === '') {
        delete this.raw['to'];
      }

      const fromAddress = this.raw.from;
      this.$store.state.web3.eth
        .sendTransaction(this.raw)
        .once('transactionHash', hash => {
          this.$store.dispatch('addNotification', [
            fromAddress,
github MyEtherWallet / MyEtherWallet / src / dapps / SecureTransaction / SecureTransaction.vue View on Github external
async getSafeSendFee() {
      try {
        this.safeSendPriceEstimate = await this.coralContract.methods
          .checkFee(unit.toWei(this.amount, 'ether').toString())
          .call();
      } catch (e) {
        this.safeSendPriceEstimate = new BigNumber(0).toFixed();
        Toast.responseHandler(e, Toast.ERROR);
      }
    }
  }
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SwapContainer / components / SwapConfirmationModal / SwapConfirmationModal.vue View on Github external
this.preparedSwap = swapDetails.dataForInitialization.map(entry => {
          entry.from = this.account.address;
          if (
            +unit.toWei(this.gasPrice, 'gwei').toString() >
            +swapDetails.kyberMaxGas
          ) {
            entry.gasPrice = swapDetails.kyberMaxGas;
          }
          return entry;
        });
      }

ethjs-unit

A simple module for handling Ethereum units (e.g. 'ether', 'wei', etc...)

MIT
Latest version published 7 years ago

Package Health Score

56 / 100
Full package analysis

Popular ethjs-unit functions