Scenario 1 — TX Sent but Reverts With “Out of Gas”
What happens
With a lower gas fee configuration (lower gasPrice or lower gasLimit), the transaction is:
successfully broadcast
TX hash is produced
…but then fails during execution.
Scenario 2 — After Increasing Gas Fee → TX Sent & Successful, But Gas Fee Extremely High (~0.4 XDC)
When we increase gasPrice (and/or gasLimit) so that the first error disappears:
What happens
The transaction is broadcast
It succeeds (no revert, no error)
But…
Problem
Discussion (6)
For the tx 0xfea1216fa41fdb5f116d6275d1dc785d... on XDC chain, the gas price is 12.5 GWei, and the used gas is 29355011(0x1bfec03), so the tx cost is 0.3669376375 XDC.
Request:
Response:
Thank you for the calculation (12.5 GWei × 29,355,011 gas = 0.3669376375 XDC).
We understand how this value is derived.
However, our main concern is not the math, but the fact that the transaction cost has been continuously increasing over time, even though:
Our smart contract code has not changed
Our input data size is the same
Our function call parameters are identical
We are performing the exact same postCertificate() operation each time
What we observed
At the beginning:
Gas used per transaction was much lower
Total transaction fee was around ~0.003 XDC
As we continued sending transactions, the gas behavior changed:
Gas used kept increasing with each certificate
Transaction cost kept rising
Now each transaction costs ~0.36 XDC, which is more than 100× higher than before
A better version:
What I changed:
studentInfo[_studentAdd].instituteNameand.uriinto a new Student with an in-place storage update:s.uri.push(_uri);s.name = _studentname;s.studentAdd = _studentAdd;Why this helps
Next recommendations (optional)
Cert.instituteto store onlyinstituteId (uint256)instead of embedding Institute to avoid repeated string writes for every certificate.mapping(uint256 => string)+ counter for very large histories.Why gasUsed grows when calling postCertificate:
uri,instituteName). As these arrays grow, any operation that reads/writes many elements costs more gas.studentInfo[addr] = Student(..., studentInfo[addr].uri, ...)forces the compiler to copy storage arrays into memory and back. That copy cost scales linearly with array length, so per-tx gasUsed increases as arrays get longer.Institute(which contains strings). Eachcertificates[hash] = Cert(institutes[id], ...)duplicates those strings into storage for every certificate, multiplying SSTOREs and increasing gas usage.CertificatePosted(string hash, ...)include strings. If logged strings or number of logs grow, log-writing gas rises.Let me look into your smart contract code on xdcscan explorer.