Merge pull request #170 from status-im/bugfix/send-gas-with-function

bug: send gas when calling a function via API
This commit is contained in:
Iuri Matias 2018-10-27 21:38:13 +02:00 committed by GitHub
commit 3007c109e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -113,9 +113,10 @@ class ContractsManager {
const abi = contract.abiDefinition.find(definition => definition.name === req.body.method);
const funcCall = (abi.constant === true || abi.stateMutability === 'view' || abi.stateMutability === 'pure') ? 'call' : 'send';
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition, address: contract.deployedAddress}, (contractObj) => {
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition, address: contract.deployedAddress}, async (contractObj) => {
try {
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account, gasPrice: req.body.gasPrice}, (error, result) => {
const gas = await contractObj.methods[req.body.method].apply(this, req.body.inputs).estimateGas();
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account, gasPrice: req.body.gasPrice, gas}, (error, result) => {
if (error) {
return res.send({result: error.message});
}