Skip to content

Commit

Permalink
fix: correct nonce calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
andskur committed May 6, 2024
1 parent 01bc9ed commit 3202065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
with:
context: .
push: true
tags: gatewayfm/eth-faucet-generic:latest
tags: gatewayfm/eth-faucet-generic:v0.0.2
13 changes: 8 additions & 5 deletions internal/chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package chain
import (
"context"
"crypto/ecdsa"
"math/big"
"strings"
"sync/atomic"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
log "github.com/sirupsen/logrus"
"math/big"
"strings"
"sync/atomic"
)

type TxBuilder interface {
Expand All @@ -26,6 +25,7 @@ type TxBuild struct {
signer types.Signer
fromAddress common.Address
nonce uint64
clientEth *ethclient.Client
}

func NewTxBuilder(provider string, privateKey *ecdsa.PrivateKey, chainID *big.Int) (TxBuilder, error) {
Expand All @@ -46,6 +46,7 @@ func NewTxBuilder(provider string, privateKey *ecdsa.PrivateKey, chainID *big.In
privateKey: privateKey,
signer: types.NewEIP155Signer(chainID),
fromAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
clientEth: client,
}
txBuilder.refreshNonce(context.Background())

Expand Down Expand Up @@ -85,6 +86,8 @@ func (b *TxBuild) Transfer(ctx context.Context, to string, value *big.Int) (comm
return common.Hash{}, err
}

log.Infof("sent tx %s to %s", signedTx.Hash(), to)

return signedTx.Hash(), nil
}

Expand All @@ -93,7 +96,7 @@ func (b *TxBuild) getAndIncrementNonce() uint64 {
}

func (b *TxBuild) refreshNonce(ctx context.Context) {
nonce, err := b.client.PendingNonceAt(ctx, b.Sender())
nonce, err := b.clientEth.NonceAt(ctx, b.Sender(), nil)
if err != nil {
log.Error("failed to refresh nonce", "address", b.Sender(), "err", err)
return
Expand Down

0 comments on commit 3202065

Please sign in to comment.