Secp256k1Pen undefined error when deploying Secret Network smart contract using secretjs library

I’m working on creating a Secret blockchain smart contract and running into an issue with my deployment script. When I try to execute my contract-deploy.js file, I get an error saying that Secp256k1Pen is undefined.

Here’s the problematic code in my deployment script:

const walletSigner = await Secp256k1Pen.fromMnemonic(seedPhrase).catch((error) => {
  throw new Error(`Failed to create wallet signer: ${error}`);
});

The error message I’m getting is:

TypeError: Cannot read properties of undefined (reading 'fromMnemonic')
    at executeDeployment (C:\Projects\secret-contract\scripts\contract-deploy.js:45:38)
    at Object.<anonymous> (C:\Projects\secret-contract\scripts\contract-deploy.js:89:5)

At the beginning of my file, I’m importing the required modules like this:

const {
  CosmWasmUtils,
  Secp256k1Pen,
  SecretNetworkClient,
  addressFromPubkey,
  pubkeyEncodeSecp256k1,
} = require("secretjs");

What could be causing this undefined property error? Has the API changed or am I missing something in my import statement?

You’ve got a compatibility issue with your secretjs version. Secp256k1Pen was deprecated and replaced with new wallet methods in newer releases. I hit the same problem upgrading from v0.x to v1.x - the wallet structure changed completely. Update your wallet creation code like this: const { Wallet } = require("secretjs"); const walletSigner = new Wallet(seedPhrase);. Need more control over wallet derivation? Try DirectSecp256k1HdWallet from @cosmjs/proto-signing. Check your package.json for your secretjs version - anything 1.0+ uses these new methods.

yeah, i’ve run into this too! secp256k1pen is kinda outdated now - you may wanna try using directsecp256k1hdwallet from @cosmjs/proto-signing instead. also, make sure to update your secretjs, since older imports can break with new versions. hope this helps!

Oh interesting, I’m curious about this too! Which version of secretjs are you running? There were major breaking changes between versions that restructured wallet creation methods.

Try using await Wallet.fromMnemonic() instead. Are you getting other import errors or just the Secp256k1Pen issue?

The secretjs docs have updated examples, but I’m not sure they cover migrating from old wallet methods. What version did you start with vs what you’re deploying on now?