I'm in the process of learning how to write smart contracts and make transactions using the Ethereum blockchain.
I'm following this tutorial and it looks like making a transaction and then adding a record of it in the blockchain are two separate actions.
I'm confused as to the gas fee that needs to be paid for making the transaction. And whether another fee needs to then be paid for adding a record of that transaction to the blockchain.
In the code I'm looking at as a tutorial, the transaction itself takes place here:
await ethereum.request({
method: "eth_sendTransaction",
params: [{
from: currentAccount,
to: addressTo,
gas: "0x5208",
value: parsedAmount._hex,
}],
});
- the developer seems to have hardcoded a value for the gas fee:
0x5208
. But isn't the value constantly changing? When the above method is called, the Metamask extension opens up and asks the user to confirm the transaction, so I guess maybe it is at that point that the user learns how much they will be paying in gas fees and the0x5208
I'm looking at above is not what I think it is ? - What if I, the developer, want to know the fee the user will be paying at that moment as well ? Is there a
ethereum.getCurrentGasFeeFor(value)
?
Once the above transaction is confirmed, then a record of that transaction is added to the blockchain here:
const transactionHash = await transactionsContract.addToBlockchain(addressTo, parsedAmount, message, keyword);
But in the above code there is no indication about the app itself (not the user) having to also pay a fee for adding a record of the transaction to the blockchain.
- I thought that (a) there is a limit on how big the record/block can be and (b) depending on the size of the record/block, the app itself would also have to pay a fee. What if in the above scenario
keyword
is a 10byte String or a 800Kb string. What will happen in either case?
I would have expected something like:
// pseudocode:
let block = { addressTo, parsedAmount, message, keyword }
let fee = ethereum.computeFeeFor(block)
if (imOkWith(fee)) {
const transactionHash = await transactionsContract.addToBlockchain(
block,
// so that the app is charged for adding this block to the blockchain
appWalletAddress: '....'
)
.....
...
} else {
dealWithTheProblemSomehow() ?
}
Thank you in advance for your help