4

In this line,

    // Set sender address or use a default if none specified
    var addr common.Address
    if args.From == nil {
        if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
            if accounts := wallets[0].Accounts(); len(accounts) > 0 {
                addr = accounts[0].Address
            }
        }
    } else {
        addr = *args.From
    }

if the from is nil, geth uses the first account of the first wallet.

  • What if I don't have any wallet/account in account manager?
  • Will it surprise the user?
  • Why is the from parameter optional?
1

This is only the Call API expose to everyone then from is not deal. The state is only temporarily for execute the call and cannot update any real state so it do no harm at all.

You can see on the comment code also

https://github.com/ethereum/go-ethereum/blob/f578d41ee6b3087f8021fd561a0b5665aea3dba6/internal/ethapi/api.go#L812

// Call executes the given transaction on the state for the given block number.
// It doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.
func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber) (hexutil.Bytes, error) {
    result, _, _, err := DoCall(ctx, s.b, args, blockNr, vm.Config{}, 5*time.Second, s.b.RPCGasCap())
    return (hexutil.Bytes)(result), err
}

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.