Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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);
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]);
};
};
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
}
},
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)
}
// 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 = [
// 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 = [
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: {
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)
}
}
}
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)
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) {