Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try{
var txCount = await web3.eth.getTransactionCount(addressFrom);
console.log('txCount',txCount)
} catch(error) { //here goes if someAsyncPromise() rejected}
console.log(error);
return error; //this will result in a resolved promise.
}
const txOptions = {
nonce: web3Utils.toHex(txCount),
gasLimit: web3Utils.toHex(25000),
gasPrice: web3Utils.toHex(2e9), // 2 Gwei
to: addressTo,
from: addressFrom,
value: web3Utils.toHex(web3Utils.toWei('123', 'wei'))
// value: web3Utils.toHex(web3Utils.toWei('123', 'wei'))
}
// fire away!
console.log('fire away ')
await this.sendSignedRawTransaction(web3,txOptions,addressFrom,account, function(err, result) {
if (err) return console.log('error', err)
console.log('sent', result)
})
},
it('should not slash valid subdomain', async () => {
let subdomain = 'legituser';
let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
let registrant = accountsArr[1];
await ENSSubdomainRegistry.methods.register(
web3Utils.sha3(subdomain),
domains.free.namehash,
utils.zeroAddress,
utils.zeroBytes32,
utils.zeroBytes32
).send({from: registrant});
let failed;
try{
await ENSSubdomainRegistry.methods.slashInvalidSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4).send()
failed = false;
} catch(e){
failed = true;
}
assert(failed, "Was slashed anyway");
});
});
const sendTransfer = async (gasPrice, verificationAddress) => {
if (!gasPrice) {
gasPrice = GAS_PRICE;
}
if (!verificationAddress) {
verificationAddress = Web3Utils.randomHex(20);
}
const txData = await escrowContract.deposit(Web3Utils.toHex(verificationAddress), {from: senderAddress, value: oneEth, gasPrice: gasPrice});
const rawTransfer = await escrowContract.getTransfer.call(verificationAddress, {from: senderAddress});
return parseTransfer(rawTransfer);
};
console.log('txData',txData);
console.log('addressFrom',addressFrom);
console.log('addressTo',addressTo);
if( estimatedGasCost > max_gas_cost){
console.log("Gas estimate too high! Something went wrong ")
return;
}
const txOptions = {
nonce: web3utils.toHex(txCount),
gas: web3utils.toHex(estimatedGasCost),
gasPrice: web3utils.toHex(web3utils.toWei(poolConfig.solutionGasPriceWei.toString(), 'gwei') ),
value: 0,
to: addressTo,
from: addressFrom,
data: txData
}
var privateKey = this.getMintingAccount().privateKey;
return new Promise(function (result,error) {
this.sendSignedRawTransaction(this.web3,txOptions,addressFrom,privateKey, function(err, res) {
if (err) error(err)
result(res)
})
async mintTokens({ state, getters, rootState, rootGetters, dispatch, commit }, { to, amount }) {
amount = amount.toString()
const gasPrice = rootState.metamask.gasPrice.standard
const { tokenInstance } = getters
const { ethAccount } = rootState.metamask
const data = tokenInstance().methods.mint(to, toWei(amount)).encodeABI()
const gas = await tokenInstance().methods.mint(to, toWei(amount)).estimateGas()
const callParams = {
method: 'eth_sendTransaction',
params: [{
from: ethAccount,
to: tokenInstance()._address,
gas: numberToHex(gas + 100000),
gasPrice: toHex(toWei(gasPrice.toString(), 'gwei')),
value: 0,
data
}],
from: ethAccount
}
const txHash = await dispatch('metamask/sendAsync', callParams, { root: true })
commit('ADD_TX', txHash)
}
}
create(params: {
recipients: Array<{ address: string; amount: string }>;
nonce: number;
gasPrice: number;
data: string;
gasLimit: number;
}) {
const { recipients, nonce, gasPrice, data, gasLimit } = params;
const { address, amount } = recipients[0];
const txData = {
nonce: utils.toHex(nonce),
gasLimit: utils.toHex(gasLimit),
gasPrice: utils.toHex(gasPrice),
to: address,
data,
value: utils.toHex(amount)
};
const rawTx = new EthereumTx(txData).serialize().toString('hex');
return rawTx;
}
exports.serializedValueTX = function(params, addr, val) {
const key = this.loadKey();
const tra = {
gasPrice: web3_utils.toHex(params['gas_price_in_gwei'] * GWEI_TO_WEI),
gasLimit: web3_utils.toHex(22000),
nonce: web3_utils.toHex(params['nonce']),
to: addr,
value: web3_utils.toHex(val),
chainId: config.network_id
};
const tx = new Tx(tra);
tx.sign(key);
return tx.serialize();
}
export const updateIssueDetail = async data => {
let returnData = { ...data }
const repoId = toHex(data.repoId)
const issueNumber = String(data.number)
const requestsData = await loadRequestsData({ repoId, issueNumber })
returnData.requestsData = requestsData
return returnData
}
create(params: {
recipients: Array<{ address: string; amount: string }>;
nonce: number;
gasPrice: number;
data: string;
gasLimit: number;
}) {
const { recipients, nonce, gasPrice, data, gasLimit } = params;
const { address, amount } = recipients[0];
const txData = {
nonce: utils.toHex(nonce),
gasLimit: utils.toHex(gasLimit),
gasPrice: utils.toHex(gasPrice),
to: address,
data,
value: utils.toHex(amount)
};
const rawTx = new EthereumTx(txData).serialize().toString('hex');
return rawTx;
}
exports.serializedTX = function(params, cntr, data) {
const key = this.loadKey();
const tra = {
gasPrice: web3_utils.toHex(params['gas_price_in_gwei'] * GWEI_TO_WEI),
gasLimit: web3_utils.toHex(config.gas_limit),
data: data,
nonce: web3_utils.toHex(params['nonce']),
to: cntr.address,
value: '0x00',
data: data,
chainId: config.network_id
};
const tx = new Tx(tra);
tx.sign(key);
return tx.serialize();
}