How to use the web3-utils.utf8ToHex 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 pelith / express-eauth / lib / Eauth.js View on Github external
checkIsValidSignature(message, signature) {
    const contractAddr = cache.get(message)
    const walletContract = new this.web3Eth.Contract(ABI, contractAddr)
    const prefixMessage = web3Utils.utf8ToHex(this.options.prefix + message)

    return walletContract.methods.isValidSignature(prefixMessage, signature).call()
    .then((magicValue) => {
      if (magicValue === '0x20c13b0b') { // '0x1626ba7e' for bytes32
        cache.del(message)
        return contractAddr
      }

      return false
    })
    .catch(err => {
      console.log(err)
      return false
    })
  }
github bodhiproject / bodhi-ui / src / stores / TransactionStore.js View on Github external
// Construct params for executing tx
      const createEventParams = [
        name,
        cloneDeep(results),
        betEndTime,
        resultSetStartTime,
        centralizedOracle,
        arbitrationOptionIndex,
        arbitrationRewardPercentage,
      ];
      // Format results to bytes32 types
      for (let i = 0; i < 3; i++) {
        if (createEventParams[1][i]) {
          createEventParams[1][i] = padRight(utf8ToHex(createEventParams[1][i]), 64);
        } else {
          createEventParams[1][i] = padRight(utf8ToHex(''), 64);
        }
      }

      // Execute tx
      const { network } = this.app.naka;
      const nbotMethods = window.naka.eth.contract(NakaBodhiToken().abi)
        .at(NakaBodhiToken()[network.toLowerCase()]);
      const txid = await this.createEvent({
        nbotMethods,
        eventParams: createEventParams,
        eventFactoryAddr: EventFactory()[network.toLowerCase()],
        escrowAmt: amountSatoshi,
        gas: 3000000,
      });
      // TODO: remove after mobile apps are done debugging
      console.log('Returned to dapp after create event');
github zapproject / zap-nodejs-api / src / api / contracts / Arbiter.js View on Github external
async initiateSubscription(
    {provider, endpoint, endpointParams, blocks, publicKey, from, gas}) {
    try {
      // Make sure we could parse it correctly
      if (endpointParams instanceof Error) {
        throw endpointParams;
      }
      for (let i in endpointParams){
        endpointParams[i] = utf8ToHex(endpointParams[i]);
      }

      return await this.contract.methods.initiateSubscription(
        provider,
        utf8ToHex(endpoint),
        endpointParams,
        toBN(publicKey),
        toBN(blocks)).send({from: from, gas: gas});
    } catch (err) {
      throw err;
    }
  }
github zapproject / zap-nodejs-api / src / api / contracts / Arbiter.js View on Github external
async initiateSubscription(
    {provider, endpoint, endpointParams, blocks, publicKey, from, gas}) {
    try {
      // Make sure we could parse it correctly
      if (endpointParams instanceof Error) {
        throw endpointParams;
      }
      for (let i in endpointParams){
        endpointParams[i] = utf8ToHex(endpointParams[i]);
      }

      return await this.contract.methods.initiateSubscription(
        provider,
        utf8ToHex(endpoint),
        endpointParams,
        toBN(publicKey),
        toBN(blocks)).send({from: from, gas: gas});
    } catch (err) {
      throw err;
    }
  }
github JoinColony / colonyJS / packages / colony-js-client / src / Colony.js View on Github external
async loadSelf(bootstrapAddress: ?string): Promise {
    if (this.ready()) return;
    await this._networkContract.loadContract(bootstrapAddress);
    // TODO: Find out version here
    const VERSION = 0;
    const result = await this._networkContract.functions.getColony(
      utf8ToHex(this.name),
    );
    const [address] = result;
    await this._colonyContract.loadContract(address, VERSION);
    this.version = VERSION;
    this.address = address;
  }
}
github JoinColony / tailor / src / modules / paramTypes / index.js View on Github external
convertInput(value: string) {
    return isHexStrict(value) ? value : utf8ToHex(value);
  },
};
github JoinColony / colonyJS / packages / colony-js-contract-client / src / modules / Validator.js View on Github external
static parseParamsValue(value: *, type: ParamTypes) {
    switch (type) {
      case 'string':
        return utf8ToHex(value);
      default:
        return value;
    }
  }
  static parseParams(params: Params) {
github enigmampc / secret-contracts / enigma-lib / Enigma.js View on Github external
                _preprocessors = preprocessors.map (p => web3Utils.utf8ToHex (p));
            }
github zapproject / zap-nodejs-api / src / api / contracts / Bondage.js View on Github external
async calcBondRate({provider, endpoint, numZap}){
    return await this.contract.methods.calcBondRate(
      provider,
      utf8ToHex(endpoint),
      toBN(numZap)
    ).call();
  }
github pelith / express-eauth / lib / Eauth.js View on Github external
confirmPersonalSignMessage(message, signature) {
    const recoveredAddress = sigUtil.recoverPersonalSignature({
      data: web3Utils.utf8ToHex(this.options.prefix + message),
      sig: signature
    })

    const storedMessage = cache.get(recoveredAddress.toLowerCase())

    if (storedMessage === message) {
      cache.del(recoveredAddress.toLowerCase())
      return recoveredAddress
    }

    return false
  }