question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

contract.callStatic.METHOD_NAME Using input/data hex

See original GitHub issue

When using the contract.callStatic.METHOD_NAME method, is it possible to use the input or data hex value provided by the transaction object to populate the method parameters instead of manually providing the parameters of the METHOD_NAME one by one?

i.e. Instead of: await wethContract.deposit({value: _amount, gasPrice: await helpers.getGasPriceFastest(), gasLimit: '1000000'}) Is it possible to do something along the lines of: contract.callStatic('0xd0e30db0') where the hexadecimal string 0xd0e30db0 includes the method_name and any other parameters needed?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ykwwZerocommented, Dec 21, 2020

Will confirm in the next few days!

1reaction
ricmoocommented, Dec 7, 2020

If you have already called populateTransaction, you can skip the contract step entirely for the callStatic and just use the provider.call. Then you can use the contract.interface.decodeFunctionResult to interpret the result. For example:

const tx = /* Your TX here */;

// This step is optional, but if the msg.sender matters in the contract function, it will be needed
if (contract.signer) { tx.signer = await TX.signer.getAddress(); }

// Sends the tx provider.call
const callResult = await contract.provider.call(tx);

try {
  // Try parsing the result:
  const result = contract.interface.decodeFunctionResult(callResult);

  // This line is only reached if the callResult represents a call that did not revert
  console.log(result);
} catch (error) {
  // Revert happened... The error will contain more info
  console.log(error);
}

I think that should work for you if you don’t want to just call the two separate methods on the contract.

I would normally just suggest you use contract.callStatic.transfer(addr, value) followed by a contract.populateTransaction.transfer(address, value) though…

Let me know if that works for you. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Decipher A Smart Contract Method Call - Medium
A smart contract can choose to simulate a method call by processing the input data in a structured way, as shown in the...
Read more >
Creating the input data for an Ethereum contract function call
The first input is dynamic so this line will describe where the data is to be found. It will be found 64 bytes...
Read more >
Ethers pass method name with parameters instead of hexdata
Is it possible to just pass method name from contract and parameters to it instead of passing this hex value? Maybe there is...
Read more >
How to mimic ethers.js callStatic with JsonRCP - Questions
I am directly constructing view/read only contract queries successfully with eth_call, now I am wondering how to call a contract state ...
Read more >
Decoding an Ethereum Transaction​.
We're going to start with a Gnosis Safe contract and a transaction a user would ... This hex value is derived from taking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found