How to use the web3-utils.isAddress function in web3-utils

To help you get started, we’ve selected a few web3-utils 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 0xbitcoin / tokenpool / lib / peer-interface.js View on Github external
getMinerData: async function(args, callback) {

             var minerEthAddress = args[0];
             var minerData = null;

             if(web3utils.isAddress(minerEthAddress.toString()) ){
                 minerData = await self.getMinerData(minerEthAddress);
             }else{
               console.log('getMinerData error: not a valid address')
             }

             var minDiff = self.getPoolMinimumShareDifficulty();

             if(minerData.varDiff <  minDiff)
             {
               minerData.varDiff  = minDiff;
             }

             // console.log('meep',minerData)
            callback(null, JSON.stringify( minerData )  );

          },
github enigmampc / secret-contracts / enigma-lib / Enigma.js View on Github external
static approveFeeBatch (tasks, options) {
        if (options && !web3Utils.isAddress (options.from)) {
            return Promise.reject ('Missing account option');
        }

        let promise = null;
        for (let i = 0; i < tasks.length; i++) {
            const task = tasks[i];
            if (!task.checkWorkerVerified ()) {
                // Don't allow computations for an unverified worker
                promise = Promise.reject ('Cannot continue with task ' + task._worker.signer +
                    'because it failed verification: ' + task._worker.verified.err);
                break;
            }
        }

        if (promise === null) {
            let fee = 0;
github ethereum / web3.js / packages / web3-core-helpers / src / formatters.js View on Github external
var outputTransactionFormatter = function (tx) {
    if (tx.blockNumber !== null)
        tx.blockNumber = utils.hexToNumber(tx.blockNumber);
    if (tx.transactionIndex !== null)
        tx.transactionIndex = utils.hexToNumber(tx.transactionIndex);
    tx.nonce = utils.hexToNumber(tx.nonce);
    tx.gas = utils.hexToNumber(tx.gas);
    tx.gasPrice = outputBigNumberFormatter(tx.gasPrice);
    tx.value = outputBigNumberFormatter(tx.value);

    if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation
        tx.to = utils.toChecksumAddress(tx.to);
    } else {
        tx.to = null; // set to `null` if invalid address
    }

    if (tx.from) {
        tx.from = utils.toChecksumAddress(tx.from);
    }

    return tx;
};
github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
let userAddress = _userAddress;

    let base = 10;
    let skillId = _skillId.toString();
    if (skillId.slice(0, 2) === "0x") {
      // We've been passed a hex string
      skillId = skillId.slice(2);
      base = 16;
    }

    let isAddress = web3Utils.isAddress(colonyAddress);
    // TODO should we return errors here?
    if (!isAddress) {
      return false;
    }
    isAddress = web3Utils.isAddress(userAddress);
    if (!isAddress) {
      return false;
    }
    if (colonyAddress.substring(0, 2) === "0x") {
      colonyAddress = colonyAddress.slice(2);
    }
    if (userAddress.substring(0, 2) === "0x") {
      userAddress = userAddress.slice(2);
    }
    colonyAddress = colonyAddress.toLowerCase();
    userAddress = userAddress.toLowerCase();
    const key = `0x${new BN(colonyAddress, 16).toString(16, 40)}${new BN(skillId.toString(), base).toString(16, 64)}${new BN(
      userAddress,
      16
    ).toString(16, 40)}`;
    return key;
github rstormsf / multisender / src / stores / tokenStore.js View on Github external
await this.web3Store.getWeb3Promise.then(async () => {
      if(Web3Utils.isAddress(this.web3Store.defaultAccount) && tokenAddress !== "0x000000000000000000000000000000000000bEEF"){
        this.tokenAddress = tokenAddress;
        await this.getDecimals(tokenAddress)
        await this.getBalance()
        await this.getAllowance()
        await this.getCurrentFee()
        this.getTokenSymbol(tokenAddress)
        this.getEthBalance()
        this.getArrayLimit()
      } else {
        this.tokenAddress = tokenAddress;
        await this.getCurrentFee()
        await this.getEthBalance()
        this.getArrayLimit()
        this.decimals = 18;
        this.defAccTokenBalance = this.ethBalance;
      }
github 0xbitcoin / 0xbitcoin-miner / lib / vault.js View on Github external
selectAccount(public_address)
    {
      if(web3Utils.isAddress(public_address))
      {
        if(this.hasAddress(public_address)){
          vaultData.selected_account_address = public_address;
          console.log('\n')
          console.log('Selected account: ', public_address)
        }else{
          //console.log('\n')
          //console.log(public_address, ' is not an ethereum address saved in your miner.  View your accounts with "account list" and select one of those.  The ability to import an account does not exist and this is a "good practice" security measure.  ' )

          account = {
                      address: public_address,
                      privateKey: null ,
                      accountType: 'readOnly'
                    }

          vaultData.account_list.push(account)
github streamr-dev / streamr-platform / app / src / marketplace / utils / validate.js View on Github external
export const isEthereumAddress = (value: string) => isAddress(value)
github citahub / cita-sdk-js / packages / cita-signer / lib / index.js View on Github external
try {
            value = value.replace(/^0x/, '');
            if (value.length % 2) {
                value = '0' + value;
            }
            const _value = exports.hex2bytes(value);
            const valueBytes = new Uint8Array(32);
            valueBytes.set(_value, 32 - _value.length);
            tx.setValue(valueBytes);
        }
        catch (err) {
            throw err;
        }
    }
    if (to) {
        if (utils.isAddress(to)) {
            tx[`setTo${_version}`](_to);
        }
        else {
            throw new Error(`Invalid to address`);
        }
    }
    if (validUntilBlock === undefined || isNaN(+validUntilBlock)) {
        throw new Error(`ValidUntilBlock should be set`);
    }
    else {
        tx.setValidUntilBlock(+validUntilBlock);
    }
    if (_chainId === undefined) {
        throw new Error(`Chain Id should be set`);
    }
    else {
github AutarkLabs / open-enterprise / apps / allocations / app / components / Panel / NewAllocation.js View on Github external
const isRecipientValid = (current) => {
  return web3Utils.isAddress(current)
}
github omisego / omg-js / packages / omg-js-rootchain / src / validators / helpers.js View on Github external
const validateAddress = Joi.string().custom(value => {
  return web3Utils.isAddress(value)
})