Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
feat(sdk): update gas price to use web3 oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
joeandrews committed Feb 5, 2020
1 parent 6653d2f commit d317dca
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/extension/src/utils/Web3Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class Web3Service {
fromAddress,
args,
web3 = this.web3,
gasPrice,
}) => {
const methodSetting = (args.length
&& typeof args[args.length - 1] === 'object'
Expand All @@ -281,15 +282,17 @@ class Web3Service {
if (type === 'call') {
return method(...methodArgs).call({
from: fromAddress,
gas: estimatedGas,
...methodSetting,
gas: estimatedGas,
gasPrice,
});
}

return new Promise(async (resolve, reject) => {
const options = {
from: fromAddress,
...methodSetting,
gasPrice,
gas: estimatedGas,
};

Expand Down Expand Up @@ -356,15 +359,25 @@ class Web3Service {
this.abis[contractName],
contractAddress || this.getAddress(contractName),
);

gsnContract.setProvider(gsnProvider);

return {
send: async (...args) => this.triggerMethod('send', {
method: gsnContract.methods[methodName],
fromAddress: signingInfo.address,
args,
web3,
}),
send: async (...args) => {
let gasPrice;
try {
gasPrice = await web3.eth.getGasPrice();
} catch (e) {
console.log(e);
}
return this.triggerMethod('send', {
method: gsnContract.methods[methodName],
fromAddress: signingInfo.address,
args,
gasPrice: gasPrice ? gasPrice * 1.3 : 18000000000, // set gas price 30% higher than last few blocks median to ensure we get in the block
web3,
});
},
};
},
};
Expand Down

0 comments on commit d317dca

Please sign in to comment.