multichain icon indicating copy to clipboard operation
multichain copied to clipboard

In the EVM client, use `PendingNonceAt` instead of `NonceAt`

Open lukerhoads opened this issue 4 years ago • 0 comments

// 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?

lukerhoads avatar Dec 10 '21 05:12 lukerhoads