Skip to content

Commit

Permalink
rawTransaction: fetch acc from privKey
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Mar 31, 2024
1 parent f53e427 commit 191154d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/envconfig/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type config struct {
BASE_TESTNET_NODE_PORT string `env:"BASE_TESTNET_NODE_PORT,required"`
BASE_TESTNET_IPFS_PORT string `env:"BASE_TESTNET_IPFS_PORT,required"`
BASE_TESTNET_GRAPH_HTTPS string `env:"BASE_TESTNET_GRAPH_HTTPS,required"`
WALLET_PRIVATE_KEY string `env:"WALLET_PRIVATE_KEY,required"`
}

var EnvVars config = config{}
Expand Down
14 changes: 10 additions & 4 deletions config/smartcontract/rawtransaction/rawtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rawtransaction

import (
"context"
"crypto/ecdsa"
"math/big"
"strings"

Expand Down Expand Up @@ -108,14 +109,19 @@ func SendRawTransactionDelegateSignature(abiS string, method string, address str
if err != nil {
return nil, err
}
mnemonic := envconfig.EnvVars.MNEMONIC
privateKey, publicKey, _, err := ethwallet.HdWallet(mnemonic) // Verify: https://iancoleman.io/bip39/
privateKey, err := crypto.HexToECDSA(envconfig.EnvVars.WALLET_PRIVATE_KEY)
if err != nil {
logwrapper.Errorf("failed to get private and public key from mnemonic, error %v", err.Error())
logwrapper.Errorf("failed to parse Private Key, error %v", err)
return nil, err
}

nonce, err := client.PendingNonceAt(context.Background(), crypto.PubkeyToAddress(*publicKey))
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
logwrapper.Errorf("cannot assert type: publicKey is not of type *ecdsa.PublicKey, error %v", err)
return nil, err
}
nonce, err := client.PendingNonceAt(context.Background(), crypto.PubkeyToAddress(*publicKeyECDSA))
if err != nil {
logwrapper.Warnf("failed to get nonce")
return nil, err
Expand Down

0 comments on commit 191154d

Please sign in to comment.