I am web3j beginner. Now I am trying to send transaction and faced this error: invalid sender
. It's related credentials, I think.
ECKeyPair keyPair = walletService.keysFromWallet(password, walletAddress);
if (keyPair == null) {
log.error("Error getting keys from wallet");
return null;
}
Credentials credentials = Credentials.create(keyPair);
And the keysFronWallet is following.
public ECKeyPair keysFromWallet(String password, String address) throws WalletNotFoundException {
byte[] entropy = this.entropyFromWallet(password, address);
// Create new key pair
ECKeyPair keyPair = bip39Service.credentialsFromEntropy(entropy).getEcKeyPair();
return keyPair;
}
Here the entropyFromWallet
is just return the entropy. it has not problem. And.
public Credentials credentialsFromEntropy(byte[] entropy) {
try {
// Generate a BIP32 master keypair from the seed
Bip32ECKeyPair masterKeypair = Bip32ECKeyPair.generateKeyPair(entropy);
// Derive the key path for the first account (m/44'/60'/0'/0/0)
// BIP44 derivation path for the first Ethereum account
int[] derivationPath = { 44 | 0x80000000, 60 | 0x80000000, 0 | 0x80000000, 0, 0 };
Bip32ECKeyPair derivedKeyPair = Bip32ECKeyPair.deriveKeyPair(masterKeypair, derivationPath);
// Create credentials
Credentials credentials = Credentials.create(derivedKeyPair);
return credentials;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
How can I solve this problem. Please help me. Thank you.