How to use the web3.utils function in web3

To help you get started, we’ve selected a few web3 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 rocket-pool / rocketpool / scripts / helpers / node-checkin.js View on Github external
module.exports = async (done) => {

    // Get command-line arguments (remove args from truffle)
    let args = process.argv.splice(4);

    // Validate arguments
    if (args.length != 2) done('Incorrect number of arguments. Please enter: node address, average load.');
    if (!Web3.utils.isAddress(args[0])) done('Node address is invalid.');

    // Parse arguments
    let [nodeAddress, averageLoad] = args;

    // Get contract dependencies
    const rocketNodeStatus = await RocketNodeStatus.deployed();

    // Estimate gas required to check in
    let gasEstimate = await rocketNodeStatus.nodeCheckin.estimateGas(averageLoad, {from: nodeAddress});

    // Check in
    let result = await rocketNodeStatus.nodeCheckin(averageLoad, {from: nodeAddress, gas: parseInt(gasEstimate) + 100000});

    // Complete
    done('Node successfully checked in: ' + args.join(', '));
github MyEtherWallet / ethereum-lists / checkToken.js View on Github external
fs.readdirSync(`${tokensDirectory}/${folder}`).forEach(file => {
      if (
        path.extname(file) === '.json' &&
        web3.utils.isAddress(file.replace('.json', ''))
      ) {
        const fullPath = `${tokensDirectory}/${folder}/${file}`;
        const obj = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
        validateObject(constraints, obj, fullPath);
        if (validate(obj, constraints) !== undefined) {
          const errs = validate(obj, constraints);
          Object.keys(errs).forEach(key => {
            console.error(
              `${errs[key][0]} for ${file} in ${tokensDirectory}/${folder}`
            );
          });
          process.exit(1);
        }
      } else {
        console.error('Incorrect file name or file extension');
        process.exit(1);
github OpenST / openst.js / lib / ContractInteract / PricerRule.js View on Github external
conversionRate,
    conversionRateDecimals,
    requiredPriceOracleDecimals
  ) {
    if (!(auxiliaryWeb3 instanceof Web3)) {
      throw new TypeError(`Mandatory Parameter 'auxiliaryWeb3' is missing or invalid: ${auxiliaryWeb3}`);
    }
    if (!Web3.utils.isAddress(organization)) {
      const err = new TypeError(`Invalid organization address ${organization}.`);
      return Promise.reject(err);
    }
    if (!Web3.utils.isAddress(eip20Token)) {
      const err = new TypeError(`Invalid eip20Token address ${eip20Token}.`);
      return Promise.reject(err);
    }
    if (!Web3.utils.isAddress(tokenRules)) {
      const err = new TypeError(`Invalid tokenRules address ${tokenRules}.`);
      return Promise.reject(err);
    }
    if (!baseCurrencyCode) {
      const err = new TypeError(`baseCurrencyCode is invalid or missing ${baseCurrencyCode}.`);
      return Promise.reject(err);
    }

    const abiBinProvider = new AbiBinProvider();
    const bin = abiBinProvider.getBIN(ContractName);

    const bytesBaseCurrencyCode = auxiliaryWeb3.utils.stringToHex(baseCurrencyCode);
    const args = [
      organization,
      eip20Token,
      bytesBaseCurrencyCode,
github RequestNetwork / requestNetwork / dist / src / servicesExternal / web3-Single.js View on Github external
Web3Single.prototype.setUpOptions = function (_options) {
        if (!_options)
            _options = {};
        if (!_options.numberOfConfirmation)
            _options.numberOfConfirmation = 0;
        if (_options.gasPrice)
            _options.gasPrice = new WEB3.utils.BN(_options.gasPrice);
        if (_options.gas)
            _options.gas = new WEB3.utils.BN(_options.gas);
        return _options;
    };
    /**
github autonomoussoftware / metronome-wallet-desktop / src / providers / MTNWalletProvider.js View on Github external
.then(({ data }) =>
        this.setState({ balance: Web3.utils.fromWei(data.balance) })
      )
github embark-framework / embark / lib / utils / utils.js View on Github external
function toChecksumAddress(address) {
  const Web3 = require('web3');
  return Web3.utils.toChecksumAddress(address);
}
github ninjadotorg / handshake-app / src / services / Wallets / Collectibles / CryptoStrikers.js View on Github external
import axios from 'axios';
import { Wallet } from '@/services/Wallets/Wallet.js';
import { StringHelper } from '@/services/helper';
import { Ethereum } from '@/services/Wallets/Ethereum.js';
import { TokenERC721 } from '@/services/Wallets/Collectibles/TokenERC721';

const Web3 = require('web3');

const BN = Web3.utils.BN;
const BigNumber = require('bignumber.js');

const EthereumTx = require('ethereumjs-tx');

const abi = require('@/contracts/Wallet/CryptoStrikers.json');

export class CryptoStrikers extends TokenERC721 {
  constructor() {
    super();
    this.className = 'CryptoStrikers';
    this.isToken = true;
    this.contractAddress = '0xdcaad9fd9a74144d226dbf94ce6162ca9f09ed7e';
    this.decimals = 0;
    this.customToken = true;
    this.title = 'CryptoStrikers';
    this.name = 'STRK';
github mosaicdao / mosaic.js / src / ContractInteract / EIP20Gateway.js View on Github external
approveBountyAmount(txOptions) {
    if (!txOptions) {
      const err = new TypeError(`Invalid transaction options: ${txOptions}.`);
      return Promise.reject(err);
    }
    if (!Web3.utils.isAddress(txOptions.from)) {
      const err = new TypeError(`Invalid from address: ${txOptions.from}.`);
      return Promise.reject(err);
    }
    return this.getBaseTokenContract().then((eip20BaseToken) => {
      return this.getBounty().then((bounty) =>
        eip20BaseToken.approve(this.address, bounty, txOptions),
      );
    });
  }
github PacktPublishing / Foundations-of-Blockchain / Chapter07 / ethereum / proof_of_ownership_app / interface / src / Main.js View on Github external
                            onClick={(e) => this.queryAsset(Web3.utils.asciiToHex(this.state.hashValue))}>
                        Check owner