3

For the sendTransaction method, will the gas cost be subtracted from the value parameter or will it be subtracted from the remaining balance of the account?

5

The transaction fee will be subtracted from account balance. When this transaction handled, at first there will buy gas and then execute transfer. In state_transaction.go file, preCheck() method would check transaction's nonce and buy gas, the buyGas() method's implement as follows:

func (st *StateTransition) buyGas() error {
    mgas := st.msg.Gas()
    if mgas.BitLen() > 64 {
        return vm.ErrOutOfGas
    }

    mgval := new(big.Int).Mul(mgas, st.gasPrice)

    var (
        state  = st.state
        sender = st.from()
    )
    if state.GetBalance(sender.Address()).Cmp(mgval) < 0 {
        return errInsufficientBalanceForGas
    }
    if err := st.gp.SubGas(mgas); err != nil {
        return err
    }
    st.gas += mgas.Uint64()

    st.initialGas.Set(mgas)
    state.SubBalance(sender.Address(), mgval)
    return nil
}

state.SubBalance(sender.Address(), mgval) shows that transaction fee is subtracted from account balance.

Hope it helps~

1

The remaining balance of the account. In order to send all your funds, you must subtract the amount from your balance and send that.

1

The Transaction cost is subtracted from the account's remaining balance. Irrespective of whether the transaction was completed successfully or not, the gas cost for the processing is deducted from the account's balance.

As clearly explained in this Github page,

Also, be advised that the amount debited from the source account will be slightly larger than that credited to the target account, which is what has been specified. The difference is a small transaction fee

A slightly larger amount will be deducted, which is the gas cost.

Your Answer

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

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