I'm in the process of learning how to write smart contracts and make transactions using the Ethereum blockchain.
I'm following your 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 your code, the transaction itself takes place here:
await ethereum.request({
method: "eth_sendTransaction",
params: [{
from: currentAccount,
to: addressTo,
gas: "0x5208",
value: parsedAmount._hex,
}],
});
- You seem 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 (I'm assuming, I haven't run the code) 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 the 0x5208
I'm looking at above is not what I think it is ?
- What if you, 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 (you the owner of the app, 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 your
keyword
is a 10byte String or a 800Kb string ?
I would have expected something like:
// pseudocode
let block = { addressTo, parsedAmount, message, keyword }
let fee = 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. I understand that this does not qualify as an issue so feel free to close it if you wish.
I have also posted this on SO.