Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethers.js calling gasPrice once again for BSC #4687

Open
tornadocontrib opened this issue Apr 14, 2024 · 7 comments
Open

ethers.js calling gasPrice once again for BSC #4687

tornadocontrib opened this issue Apr 14, 2024 · 7 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@tornadocontrib
Copy link

tornadocontrib commented Apr 14, 2024

Describe the Problem

Fixed by #4686

@tornadocontrib tornadocontrib added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Apr 14, 2024
@mahatotarit
Copy link

The result changes depending on which network you use.

Example -

const ethers = require('ethers');

async function getGasPrice() {
    const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/'); // For BSC network

// const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID');  // For ethereum main network

    const gasPrice = await provider.getGasPrice();
    console.log("Current gas price:", ethers.utils.formatUnits(gasPrice, 'gwei'), "gwei");
}

getGasPrice();

@ricmoo
Copy link
Member

ricmoo commented Apr 22, 2024

Yes. The gas price depends on network; that’s just how gas works. :)

Ethereum uses EIP-1337, so the fees are protocol defined (based on recent block congestion).

BSC uses a bidding system, so the miners choose the gas price based on what a transaction is willing to pay.

@tornadocontrib
Copy link
Author

@mahatotarit @ricmoo Yes, but the problem is that current code will just send request to node even when I already specify the gasPrice and it is odd since when there is already a gasPrice ethers.js wouldn't apply it so why sending an additional request when we wouldn't override them?

@ricmoo
Copy link
Member

ricmoo commented Apr 22, 2024

@tornadocontrib I agree that is something I will optimize. My previous comment was regarding the comment by @mahatotarit.

I’m working on it. It just takes time. :)

@tornadocontrib
Copy link
Author

@ricmoo BTW, is there any specific reason to block "from" field for Transaction.from method?

I think it would be helpful to restrict transaction being signed by a specific signer but don't know if it would be appropriate.

@ricmoo
Copy link
Member

ricmoo commented Apr 23, 2024

@tornadocontrib You can specify from in a TransactionRequest, but the Transaction is a living object; so the from is calculated from the tx details and the signature.

For example, when you set the value, then getting the .serialized now contains the updated value. What would it mean if you set the from field? It would require that the signature be updated, which would require the private key, which a Transaction doesn’t (and shouldn’t) have.

The key thing to keep in mind is that there isn’t actually a from in a transaction. The JSON-RPC includes it as a hint to the client, but the tx from address is computed via ecrecover, so it is entirely an implied property. But that’s why other Transaction-ish objects (like TransactionRequest and TransactionResponse) include it. :)

Does that make sense?

@tornadocontrib
Copy link
Author

@ricmoo Yes, didn't notice since I haven't read the full codebase but thanks for clarification, was working on the transaction serialization for offline signing though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants