How to use the web3.prototype 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 mosaicdao / mosaic.js / lib / geth.js View on Github external
Geth.ValueChainWS = new Web3( VC_WS );
Geth.ValueChainWS._id = "VC_WS";

Geth.UtilityChain = new Web3(new Web3.providers.HttpProvider( UC_RPC ));
Geth.UtilityChain._id = "UC";

const DEF_DEPLOY_GAS = 4000000;

/** Helper for deploying a contract, if changed.
 * @param {string} sender Address of sender
 * @param {object} contract Contract JSON
 * @param {string?} oldAddress Old address of this contract
 * @param {Object} args Optional constructor arguments
 * @returns {Promise} Resolves to address of contract
 */
Web3.prototype.deployContract = function(sender, contract, oldAddress, ...args) {
    const minimumGasPrice = 100;
    const forceRedeployContract = true;
    const newCodeWithCtor = "0x" + contract.bin;
    return Promise.resolve()
        .then(_ => oldAddress ? this.eth.getCode(oldAddress) : "")
        .then(oldCode => {
            if (oldCode.length > 2 && newCodeWithCtor.endsWith(oldCode.substr(2)) && !forceRedeployContract ) { 
                // console.log("Skipped: contract body unchanged; constructor/args might have changed though!");
                return oldAddress;
            }
            else {
                return this.eth.personal.unlockAccount(sender)
                    // unlockAccount always fails under testrpc
                    .catch(err => console.error(this._id, err.message || err))
                    .then(success => {
                        const abi = JSON.parse(contract.abi);
github mosaicdao / mosaic.js / providers / OriginWeb3.js View on Github external
// let _instances = {};

const OriginWeb3 = function() {
  const oThis = this,
    provider = oThis.ic().configStrategy.origin.provider;

  console.log('OriginWeb3 provider', provider);

  Web3.call(oThis, provider);

  // Bind send method with signer.
  oThis.bindSigner();
};

if (Web3.prototype) {
  OriginWeb3.prototype = Object.create(Web3.prototype);
} else {
  OriginWeb3.prototype = {};
}
OriginWeb3.prototype.constructor = OriginWeb3;

OriginWeb3.prototype.signerServiceInteract = function () {
  const oThis = this;

  let signers = oThis.ic().Signers();
  return signers.getOriginSignerService();
};


signerServiceBinder( OriginWeb3.prototype );
InstanceComposer.registerShadowableClass(OriginWeb3, 'OriginWeb3');
github mjhm / create-react-dapp / template / src / helpers / Voting.js View on Github external
import Promise from 'bluebird';
import Web3 from 'web3';
import _ from 'lodash';

const { asciiToHex, hexToAscii } =
  // web3 1.X
  Web3.utils || {
    // web3 0.20.X
    asciiToHex: Web3.prototype.fromAscii,
    hexToAscii: Web3.prototype.toAscii,
  };

export default class Voting {
  constructor(contract) {
    this.contract = contract;

    const getCandidateList = Promise.promisify(
      this.contract.getCandidateList.call,
      { context: this.contract.getCandidateList },
    );
    const totalVotesFor = Promise.promisify(this.contract.totalVotesFor.call, {
      context: this.contract.totalVotesFor,
    });
    const voteForCandidate = Promise.promisify(
      this.contract.voteForCandidate.sendTransaction,
github PolymathNetwork / polymath.js-deprecated / src / contract_wrappers / Customers.js View on Github external
async verifyCustomer(
    // ownerAddress: string,
    kycProviderAddress: string,
    customerAddress: string,
    countryJurisdiction: string,
    divisionJurisdiction: string,
    role: CustomerRole,
    accredited: boolean,
    expires: BigNumber,
  ) {
    await this._contract.verifyCustomer(
      customerAddress,
      Web3.prototype.fromAscii(countryJurisdiction),
      Web3.prototype.fromAscii(divisionJurisdiction),
      new BigNumber(roleToNumber(role)),
      accredited,
      expires,
      {
        from: kycProviderAddress,
        gas: 2500000,
      },
    );
  }
github mjhm / create-react-dapp / template / dapp / migrations / 2_voting.js View on Github external
const deployInfo = require('../helpers/deployInfo');
const Web3 = require('web3');
const Voting = artifacts.require('Voting');
const asciiToHex = (Web3.utils || {}).asciiToHex || Web3.prototype.fromAscii;
//                 ^^^ web3 1.x                     ^^^ web3 0.20.X

const candidates = ['Rama', 'Nick', 'Jose'];

module.exports = async deployer => {
  await deployer.deploy(Voting, candidates.map(asciiToHex));
  return deployInfo(deployer, Voting);
};
github poanetwork / poa-popa / web-dapp / server-lib / buildSignature.js View on Github external
function buildSignature(params, privateKey) {
    const priceWei = Web3.prototype.padLeft(Web3.prototype.toBigNumber(params.priceWei).toString(16), 64);
    
    const text2sign =
        params.wallet +
        Buffer.concat([
            Buffer.from(params.name, 'utf8'),
            Buffer.from(params.country, 'utf8'),
            Buffer.from(params.state, 'utf8'),
            Buffer.from(params.city, 'utf8'),
            Buffer.from(params.address, 'utf8'),
            Buffer.from(params.zip, 'utf8'),
            Buffer.from(priceWei, 'hex'),
            Buffer.from(params.sha3cc.substr(2), 'hex'),
        ]).toString('hex');
    
    return sign(text2sign, privateKey);
}
github ostdotcom / base / lib / ost_web3 / ost-web3.js View on Github external
.then(function(result) {
        logger.info(`[${oThis.endPointUrl}] heartbeat successful. latest block number:: ${result}`);
      })
      .catch(function(reason) {
        logger.error(`[${oThis.endPointUrl}] WS ping failed. reason :: `, reason);
      })
      .then(function() {
        setTimeout(function() {
          oThis.providerHeartbeat();
        }, oThis.providerOptions.providerPollingInterval);
      });
  }
};

//Take care of prototype
OSTWeb3.prototype = Object.assign(OSTWeb3Proto, Web3.prototype);

//Take care of all static properties of Web3.
(function() {
  function addProp(prop) {
    Object.defineProperty(OSTWeb3, prop, {
      get: function() {
        return Web3[prop];
      },
      set: function(newValue) {
        Web3[prop] = newValue;
      }
    });
  }
  for (var prop in Web3) {
    addProp(prop);
  }
github OpenST / openst.js / lib / providers / web3 / ChainWeb3.js View on Github external
}
  //__NOT_FOR_WEB__END__

  Web3.call(oThis, provider, net);

  //Bind send method with signer.
  oThis.bindSignerService();

  //Per-warm Connections.
  let socketCnt = maxHttpScokets;
  while (socketCnt--) {
    oThis.eth.getBlockNumber();
  }
};

if (Web3.prototype) {
  ChainWeb3.prototype = Object.create(Web3.prototype);
} else {
  ChainWeb3.prototype = {};
}

ChainWeb3.prototype.signerServiceInteract = function() {
  const oThis = this;

  let signers = oThis.ic().Signers();
  return signers.getSignerService();
};

signerServiceBinder(ChainWeb3.prototype);
InstanceComposer.register(ChainWeb3, 'chainWeb3', true);

module.exports = ChainWeb3;
github PolymathNetwork / polymath.js-deprecated / src / contract_wrappers / Compliance.js View on Github external
async createTemplate(
    legalDelegateAddress: string,
    offeringType: string,
    issuerJurisdiction: string,
    accredited: boolean,
    kycProviderAddress: string,
    details: string,
    expires: BigNumber,
    fee: BigNumber,
    quorum: BigNumber,
    vestingPeriod: BigNumber,
  ): Promise<template> {
    const receipt = await this._contract.createTemplate(
      offeringType,
      Web3.prototype.fromAscii(issuerJurisdiction),
      accredited,
      kycProviderAddress,
      details,
      expires,
      fee,
      quorum,
      vestingPeriod,
      {
        from: legalDelegateAddress,
        gas: 4000000,
      },
    );
    const logs = receipt.logs.filter(log =&gt; log.event === 'LogTemplateCreated');

    if (logs.length === 0) {
      throw new Error('createTemplate couldn\'t find an event log.');</template>
github PolymathNetwork / polymath.js-deprecated / src / cli / index.js View on Github external
function hashSource(source) {
  return Web3.prototype.sha3(source);
}