Skip to content

In the EVM client, use PendingNonceAt instead of NonceAt #137

@lukerhoads

Description

@lukerhoads
// AccountNonce returns the current nonce of the account. This is the nonce to
// be used while building a new transaction.
func (client *Client) AccountNonce(ctx context.Context, addr address.Address) (pack.U256, error) {
	targetAddr, err := NewAddressFromHex(string(pack.String(addr)))
	if err != nil {
		return pack.U256{}, fmt.Errorf("bad to address '%v': %v", addr, err)
	}
	nonce, err := client.EthClient.NonceAt(ctx, common.Address(targetAddr), nil)
	if err != nil {
		return pack.U256{}, fmt.Errorf("failed to get nonce for '%v': %v", addr, err)
	}

	return pack.NewU256FromU64(pack.NewU64(nonce)), nil
}

Shouldn't this function use PendingNonceAt? After all, the comment above says that it should be used to craft the next Tx, but in Ethereum docs (https://pkg.go.dev/github.com/ethereum/go-ethereum/ethclient#Client.PendingNonceAt) it says to use PendingNonceAt. Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions