1

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.

1 Answer 1

1
+50

I found why this error occurs. Above codes have no mistake. This error came from wrong chain Id. After using the correct chain id, the error is disappeared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.