0

I'm creating a smart contract that does the following:

  • Checks that a userID parameter is included as data field OR
  • that the last 4 zeros of the amount being sent is not equal to zero (i.e, 0.1230000000000001234 is OK. 0.1230000000000000000 or 0.1230000000000001004 are not OK)

...

 function accept() public payable {
        require(msg.value == 0.00000000000000XXXX);
        // X means non zero
    }

If neither of the above rules are satisfied the contract "rejects" the transaction. If either of the above is satisfied the total amount is forwarded to a EOA (assume to an address with a non zero balance)

I'm trying to calculate the estimated gas costs in each of the following scenarios:

When the Transaction Succeeds:

In this case, the gas costs can be calculated as follows:

  • 21,000 base gas cost

  • the fee to invoke the smart contract which evaluates whether userID/wei marker are present (which I believe is < 500 gwei according to this document)

  • the fee for each byte of data that is included in the transaction (such as a userID) which is approx. 68 gwei per byte (we could assume max of 1 byte for the userID)

  • the fee for the smart contract to transfer/forward funds to the EOA for invoking send or transfer or call.value().gas function. According to this thread the fee is fixed at 2,300

  • In addition, as the creator of the contract I would pay a one time fee for deployment

So 21,000 + (approx.) 500 + 68 + 2,300 = 28,068.

When the Transaction Fails:

If neither of the two conditions are satisfied, the transaction would be rejected by the contract (so the funds would not be forwarded) but the sender would still need to pay:

  • a fee for invoking above function (approx. 500)

  • (??) the base fee of 21,000?

  • In addition, as the creator of the contract I would pay a one time fee for deployment

Does the sender still pay 21,000 base fee when the transaction is aborted?

Do I have the correct approach in calculating the fee in each of the above scenarios?

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.