I am building a Secret NFT and I'm following this tutorial https://youtu.be/jRuSOos9ig4. I tried to deploy the NFT like this video narrator does around 31:12. I ran a the deploy-nft.js file that failed at this line:
const signingPen = await Secp256k1Pen.fromMnemonic(mnemonic).catch((err) => {
throw new Error(`Could not get signing pen: ${err}`);
});
With this error:
TypeError: Cannot read properties of undefined (reading 'fromMnemonic')
at main (C:\Users\nyusername\path\to\secret-nft-two\contract\deploy-nft.js:40:43)
at Object.<anonymous> (C:\Users\nyusername\path\to\secret-nft-two\contract\deploy-nft.js:94:3)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
I imported Secp256k1Pen at the top of the file like this:
const {
EnigmaUtils,
Secp256k1Pen,
SigningCosmWasmClient,
pubkeyToAddress,
encodeSecp256k1Pubkey,
} = require("secretjs");
So why is it failing with this error?
Secret.js https://secretjs.scrt.network/ appears to have removed Secp256k1Pen as one of its exports.
Instead you create the client object that's capable of signing like this:
const wallet = new Wallet(process.env.MNEMONIC);
const secretjs = new SecretNetworkClient({
url: process.env.SECRET_REST_URL,
wallet: wallet,
walletAddress: wallet.address,
chainId: process.env.VITE_SECRET_CHAIN_ID,
});
And you sign a transaction like this (this is a contract upload transaction):
const wasm = fs.readFileSync('my-snip721/contract.wasm.gz');
console.log('Uploading contract');
const tx = await secretjs.tx.compute.storeCode(
{
sender: wallet.address,
wasm_byte_code: wasm,
source: "https://github.com/baedrik/snip721-reference-impl",
builder: "",
},
{
gasLimit: 4_000_000,
}
);