Open
Description
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 which 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");
The entire file incorporating the above code looks like this:
const {
EnigmaUtils,
Secp256k1Pen,
SigningCosmWasmClient,
pubkeyToAddress,
encodeSecp256k1Pubkey,
} = require("secretjs");
const fs = require("fs");
// Load environment variables
require("dotenv").config();
const customFees = {
upload: {
amount: [{ amount: "5000000", denom: "uscrt" }],
gas: "5000000",
},
init: {
amount: [{ amount: "500000", denom: "uscrt" }],
gas: "500000",
},
exec: {
amount: [{ amount: "500000", denom: "uscrt" }],
gas: "500000",
},
send: {
amount: [{ amount: "80000", denom: "uscrt" }],
gas: "80000",
},
};
const main = async () => {
const httpUrl = process.env.__VITE_SECRET_REST_URL;
// Use key created in tutorial #2
const mnemonic = process.env.VITE_MNEMONIC;
// A pen is the most basic tool you can think of for signing.
// This wraps a single keypair and allows for signing.
const signingPen = await Secp256k1Pen.fromMnemonic(mnemonic).catch((err) => {
throw new Error(`Could not get signing pen: ${err}`);
});
// Get the public key
const pubkey = encodeSecp256k1Pubkey(signingPen.pubkey);
// get the wallet address
const accAddress = pubkeyToAddress(pubkey, "secret");
// 1. Initialize client
const txEncryptionSeed = EnigmaUtils.GenerateNewSeed();
const client = new SigningCosmWasmClient(
httpUrl,
accAddress,
(signBytes) => signingPen.sign(signBytes),
txEncryptionSeed, customFees,
);
console.log(`Wallet address=${accAddress}`);
// 2. Upload the contract wasm
const wasm = fs.readFileSync('my-snip721/contract.wasm');
console.log('Uploading contract');
const uploadReceipt = await client.upload(wasm, {})
.catch((err) => { throw new Error(`Could not upload contract: ${err}`); });
// Get the code ID from the receipt
const { codeId } = uploadReceipt;
const initMsg = {
/// name of token contract
name: process.env.CONTRACT_NAME,
/// token contract symbol
symbol: process.env.CONTACT_SYMBOL,
/// entropy used for prng seed
entropy: process.env.RANDOM_LOWERCASE_LETTERS_SEED,
/// optional privacy configuration for the contract
config: {
public_owner: true
},
}
const contract = await client
.instantiate(
codeId,
initMsg,
`My Snip721${Math.ceil(Math.random() * 10000)}`
)
.catch((err) => {
throw new Error(`Could not instantiate contract: ${err}`);
});
const { contractAddress } = contract;
console.log("contract: ", contract, "address:", contractAddress);
};
main().catch((err) => {
console.error(err);
});
And I run this file with node deploy-nft.js
. Also according to my package.json file, I'm using "secretjs": "^1.6.13"
So why is it failing with this error? Is secret.js not properly exposing Secp256k1Pen?
Metadata
Metadata
Assignees
Labels
No labels