How to use the web3-eth-contract.prototype function in web3-eth-contract

To help you get started, we’ve selected a few web3-eth-contract 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 ethereum / web3.js / packages / web3-eth / src / index.js View on Github external
// the contract instances
        var _this = this;
        var setProvider = self.setProvider;
        self.setProvider = function() {
          setProvider.apply(self, arguments);
          core.packageInit(_this, [self.currentProvider]);
        };
    };

    Contract.setProvider = function() {
        BaseContract.setProvider.apply(this, arguments);
    };

    // make our proxy Contract inherit from web3-eth-contract so that it has all
    // the right functionality and so that instanceof and friends work properly
    Contract.prototype = Object.create(BaseContract.prototype);
    Contract.prototype.constructor = Contract;

    // add contract
    this.Contract = Contract;
    this.Contract.defaultAccount = this.defaultAccount;
    this.Contract.defaultBlock = this.defaultBlock;
    this.Contract.setProvider(this.currentProvider, this.accounts);

    // add IBAN
    this.Iban = Iban;

    // add ABI
    this.abi = abi;

    // add ENS
    this.ens = new ENS(this);
github citahub / cita-sdk-js / packages / cita-sdk / src / contract / index.ts View on Github external
const Method = require('web3-core-method')
const utils = require('web3-utils')
const { formatters } = require('web3-core-helpers')
const promiEvent = require('web3-core-promievent')

enum Action {
  NONE = '',
  CALL = 'call',
  SEND = 'send',
  SEND_TRANSACTION = 'sendTransaction'
}
const sign = (_tx: any) => {
  const tx = addPrivateKeyFrom(Contract.accounts.wallet)(_tx)
  return signer(tx)
}
Contract.prototype._executeMethod = function _executeMethod() {
  const ctx = this
  let args: any = this._parent._processExecuteArguments.call(
    this,
    Array.prototype.slice.call(arguments),
    defer
  )
  var defer: any = promiEvent(args.type !== 'send')
  const ethAccounts = ctx.constructor._ethAccounts || ctx._ethAccounts

  // simple return request for batch requests
  if (args.generateRequest) {
    const payload = {
      params: [formatters.inputCallFormatter.call(this._parent, args.options)],
      callback: args.callback,
      method: '',
      format: null
github citahub / cita-sdk-js / packages / cita-sdk / src / contract / index.ts View on Github external
}
    },
    type: 'eth',
    requestManager: this._requestManager
  })
  subscription.subscribe(
    'logs',
    subOptions.params,
    subOptions.callback || function() {}
  )

  return subscription
}

// getPastLogs RPC
Contract.prototype.getPastEvents = function() {
  const subOptions = this._generateEventOptions.apply(this, arguments)

  let getPastLogs = new Method({
    name: 'getPastLogs',
    call: 'getLogs',
    params: 1,
    inputFormatter: [formatters.inputLogFormatter],
    outputFormatter: this._decodeEventABI.bind(subOptions.event)
  })
  getPastLogs.setRequestManager(this._requestManager)
  const call = getPastLogs.buildCall()

  getPastLogs = null

  return call(subOptions.params, subOptions.callback)
}
github poanetwork / tokenbridge / ui / lib / web3-eth / index.js View on Github external
// create a proxy Contract type for this instance, as a Contract's provider
    // is stored as a class member rather than an instance variable. If we do
    // not create this proxy type, changing the provider in one instance of
    // web3-eth would subsequently change the provider for _all_ contract
    // instances!
    var Contract = function Contract() {
        BaseContract.apply(this, arguments);
    };

    Contract.setProvider = function() {
        BaseContract.setProvider.apply(this, arguments);
    };

    // make our proxy Contract inherit from web3-eth-contract so that it has all
    // the right functionality and so that instanceof and friends work properly
    Contract.prototype = Object.create(BaseContract.prototype);
    Contract.prototype.constructor = Contract;

    // add contract
    this.Contract = Contract;
    this.Contract.defaultAccount = this.defaultAccount;
    this.Contract.defaultBlock = this.defaultBlock;
    this.Contract.setProvider(this.currentProvider, this.accounts);

    // add IBAN
    this.Iban = Iban;

    // add ABI
    this.abi = abi;


    var methods = [
github poanetwork / bridge-ui / lib / web3-eth / index.js View on Github external
// create a proxy Contract type for this instance, as a Contract's provider
    // is stored as a class member rather than an instance variable. If we do
    // not create this proxy type, changing the provider in one instance of
    // web3-eth would subsequently change the provider for _all_ contract
    // instances!
    var Contract = function Contract() {
        BaseContract.apply(this, arguments);
    };

    Contract.setProvider = function() {
        BaseContract.setProvider.apply(this, arguments);
    };

    // make our proxy Contract inherit from web3-eth-contract so that it has all
    // the right functionality and so that instanceof and friends work properly
    Contract.prototype = Object.create(BaseContract.prototype);
    Contract.prototype.constructor = Contract;

    // add contract
    this.Contract = Contract;
    this.Contract.defaultAccount = this.defaultAccount;
    this.Contract.defaultBlock = this.defaultBlock;
    this.Contract.setProvider(this.currentProvider, this.accounts);

    // add IBAN
    this.Iban = Iban;

    // add ABI
    this.abi = abi;


    var methods = [
github citahub / cita-sdk-js / packages / cita-sdk / src / contract / index.ts View on Github external
params: 1,
          inputFormatter: [sign],
          requestManager: ctx._parent._requestManager,
          accounts: Contract.accounts, // is eth.accounts (necessary for wallet signing)
          defaultAccount: ctx._parent.defaultAccount,
          defaultBlock: ctx._parent.defaultBlock,
          extraFormatters: extraFormatters
        }).createFunction()

        return sendTransaction(args.options, args.callback)
    }
  }
}

// get past log subscription
Contract.prototype._on = function() {
  const ctx = this
  var subOptions = this._generateEventOptions.apply(this, arguments)

  // prevent the event "newListener" and "removeListener" from being overwritten
  this._checkListener('newListener', subOptions.event.name, subOptions.callback)
  this._checkListener(
    'removeListener',
    subOptions.event.name,
    subOptions.callback
  )

  // TODO check if listener already exists? and reuse subscription if options are the same.

  // create new subscription
  var subscription = new Subscription({
    subscription: {
github citahub / cita-sdk-js / packages / cita-sdk / lib / contract / index.js View on Github external
}
                else {
                    ctx.emit('data', output);
                }
                if (_.isFunction(ctx.callback)) {
                    ctx.callback(null, output, this);
                }
            }
        },
        type: 'eth',
        requestManager: this._requestManager
    });
    subscription.subscribe('logs', subOptions.params, subOptions.callback || function () { });
    return subscription;
};
Contract.prototype.getPastEvents = function () {
    const subOptions = this._generateEventOptions.apply(this, arguments);
    let getPastLogs = new Method({
        name: 'getPastLogs',
        call: 'getLogs',
        params: 1,
        inputFormatter: [formatters.inputLogFormatter],
        outputFormatter: this._decodeEventABI.bind(subOptions.event)
    });
    getPastLogs.setRequestManager(this._requestManager);
    const call = getPastLogs.buildCall();
    getPastLogs = null;
    return call(subOptions.params, subOptions.callback);
};
exports.default = Contract;
github citahub / cita-sdk-js / packages / cita-sdk / lib / contract / index.js View on Github external
const sendTransaction = new Method({
                    name: 'sendTransaction',
                    call: Action.SEND_TRANSACTION,
                    params: 1,
                    inputFormatter: [sign],
                    requestManager: ctx._parent._requestManager,
                    accounts: Contract.accounts,
                    defaultAccount: ctx._parent.defaultAccount,
                    defaultBlock: ctx._parent.defaultBlock,
                    extraFormatters: extraFormatters
                }).createFunction();
                return sendTransaction(args.options, args.callback);
        }
    }
};
Contract.prototype._on = function () {
    const ctx = this;
    var subOptions = this._generateEventOptions.apply(this, arguments);
    this._checkListener('newListener', subOptions.event.name, subOptions.callback);
    this._checkListener('removeListener', subOptions.event.name, subOptions.callback);
    var subscription = new subscription_1.default({
        subscription: {
            params: 1,
            inputFormatter: [formatters.inputLogFormatter],
            outputFormatter: this._decodeEventABI.bind(subOptions.event),
            subscriptionHandler: function (output) {
                if (output.removed) {
                    ctx.emit('changed', output);
                }
                else {
                    ctx.emit('data', output);
                }
github citahub / cita-sdk-js / packages / cita-sdk / lib / contract / index.js View on Github external
const Method = require('web3-core-method');
const utils = require('web3-utils');
const { formatters } = require('web3-core-helpers');
const promiEvent = require('web3-core-promievent');
var Action;
(function (Action) {
    Action["NONE"] = "";
    Action["CALL"] = "call";
    Action["SEND"] = "send";
    Action["SEND_TRANSACTION"] = "sendTransaction";
})(Action || (Action = {}));
const sign = (_tx) => {
    const tx = addPrivateKey_1.default(Contract.accounts.wallet)(_tx);
    return cita_signer_1.default(tx);
};
Contract.prototype._executeMethod = function _executeMethod() {
    const ctx = this;
    let args = this._parent._processExecuteArguments.call(this, Array.prototype.slice.call(arguments), defer);
    var defer = promiEvent(args.type !== 'send');
    const ethAccounts = ctx.constructor._ethAccounts || ctx._ethAccounts;
    if (args.generateRequest) {
        const payload = {
            params: [formatters.inputCallFormatter.call(this._parent, args.options)],
            callback: args.callback,
            method: '',
            format: null
        };
        if (args.type === Action.CALL) {
            payload.params.push(formatters.inputDefaultBlockNumberFormatter.call(this._parent, args.defaultBlock));
            payload.method = Action.CALL;
            payload.format = this._parent._decodeMethodReturn.bind(null, this._method.outputs);
        }

web3-eth-contract

Web3 module to interact with Ethereum smart contracts.

LGPL-3.0
Latest version published 21 days ago

Package Health Score

79 / 100
Full package analysis

Similar packages