How to use web3-eth-contract - 10 common examples

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 ethereum / web3.js / packages / web3-eth / src / index.js View on Github external
var Contract = function Contract() {
        BaseContract.apply(this, arguments);

        // when Eth.setProvider is called, call packageInit
        // on all contract instances instantiated via this Eth
        // instances. This will update the currentProvider for
        // the contract instances
        var _this = this;
        var setProvider = self.setProvider;
        self.setProvider = function() {
          setProvider.apply(self, arguments);
          core.packageInit(_this, [self.currentProvider]);
        };
    };
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 / src / contract / index.ts View on Github external
return receipt
          },
          contractDeployFormatter: (receipt: any) => {
            const newContract = ctx._parent.clone()
            newContract.options.address = receipt.contractAddress
            return newContract
          }
        }

        const sendTransaction = new Method({
          name: 'sendTransaction',
          call: Action.SEND_TRANSACTION,
          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)
    }
  }
}
github floating / frame / test / radSpecWithValue.js View on Github external
const main = async () => {
  try {
    const ethereum = provider()
    const accounts = await ethereum.send('eth_accounts')
    console.log({ accounts })
    Web3EthContract.setProvider(ethereum)

    const antContract = new Web3EthContract(
      abi,
      '0x960b236A07cf122663c4303350609A66A7B288C0'
    )

    const result = await antContract.methods.transfer(
      '0xfD85b83369E72512A34E23fc575b96761a11F9fD', '100000000'
    ).send({
      from: accounts[0],
      gasPrice: 1000000,
      gas: 8000000,
      value: '1000000000000000'
    })

    console.log(result)
github floating / frame / test / radSpec.js View on Github external
const main = async () => {
  try {
    const ethereum = provider()
    const accounts = await ethereum.send('eth_accounts')
    console.log({ accounts })
    Web3EthContract.setProvider(ethereum)

    const antContract = new Web3EthContract(
      abi,
      '0x960b236A07cf122663c4303350609A66A7B288C0'
    )

    const result = await antContract.methods.transfer(
      '0xfD85b83369E72512A34E23fc575b96761a11F9fD', '100000000'
    ).send({
      from: accounts[0],
      gasPrice: 1000000,
      gas: 8000000
    })

    console.log(result)
  } catch (e) {

web3-eth-contract

Web3 module to interact with Ethereum smart contracts.

LGPL-3.0
Latest version published 11 days ago

Package Health Score

79 / 100
Full package analysis

Similar packages