1

If two transactions has the same gas fees, I want to transaction which has minimum gas fees should have priority.

uint minersTip = tx.gasprice - block.basefee;

Here is transferForm method. Can i add priority to this one?

function transferFrom(
    address _from,
    address _to,
    uint256 _value
) public returns (bool) {
    if (_to == address(0)) revert();
    if (_value > balances[_from]) revert();
    if (_value > allowed[_from][msg.sender]) revert();
    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
    emit Result(_from, _to, _value, balances[_from], balances[_to]);
    return true;
}

1 Answer 1

1

You can't do that.

The transactions are ordered and then executed serially in a single thread, so txn A cannot have any knowledge of txn B, nor can a contract influence the order.

What you can do is implement business rules about allowable ordering, rejecting any transactions that arrive out of sequence.

You can enforce "on your marks", "get set", and "go", in that order. You can enforce only "set" runners may "go", or only the owner may start the race.

If you allow a race condition, e.g. "first over the line", you do not get to influence which txn will win. Even participants who bid aggressively will find the outcome is far from certain.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.