Solana Candy machine TypeError: Cannot read properties of undefined (reading '_bn') - windows-10

I'm following this article as a practice.
ts-node packages/cli/src/candy-machine-cli.ts verify --env devnet --keypair "C:\Windows\System32\~\.config\solana\devnet.json"
While trying to verify candy machine, I ran into
TypeError: Cannot read properties of undefined (reading '_bn')
at isPublicKeyData (C:\Users\my-userName\Source\Repos\metaplex\js\node_modules#solana\web3.js\src\publickey.ts:29:35)
at new PublicKey (C:\Users\my-userName\Source\Repos\metaplex\js\node_modules#solana\web3.js\src\publickey.ts:45:9)
at C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:326:27
at step (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:64:23)
at Object.next (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:45:53)
at fulfilled (C:\Users\my-userName\Source\Repos\metaplex\js\packages\cli\src\candy-machine-cli.ts:36:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
By a quick search on the internet, some people say I need to first create the candy machine. So I ran
ts-node packages/cli/src/candy-machine-cli.ts create_candy_machine --env devnet --keypair "C:\Windows\System32\~\.config\solana\devnet.json"
But it gave me the same error.
Appreciate any advice about how I may solve this.

While trying to resolve another issue, I found the problem has something to do with the ts-node version that I was using.
Problem solved after update with command below
npm i ts-node#latest

You need to provide a public key for getNameAccountKey, e.g.
import { Connection, PublicKey } from '#solana/web3.js';
import { getHashedName, getNameAccountKey, NameRegistryState } from '#solana/spl-name-service';
...
class SomeClass {
constructor(private readonly configService: ConfigService) {
this.publicKey = new PublicKey(
this.configService.get('SOLANA_NAME_SERVICE_PUBLIC_KEY'), // that public key taken from `.env` config file
);
}
...
private async resolveSnsName(name: string, connection: Connection): Promise<string> {
try {
const parsedName = name.replace('.sol', '');
const hashedName = await getHashedName(parsedName);
const domainKey = await getNameAccountKey(hashedName, undefined, this.publicKey);
const registry = await NameRegistryState.retrieve(connection, domainKey);
return registry.owner.toBase58();
} catch {
return null;
}
}
}

For anyone who sees this from now on (at least until any other update makes this obsolete), you can also get this error simply because you're trying to create a Candy Machine v1, which I was told on the Metaplex discord won't work anymore.
Make sure you follow the steps for using v2 (as of the date I write this), as covered in the official docs here: https://docs.metaplex.com/candy-machine-v2/configuration. You'll simply use a different command for the v2 package.
Look over the docs to check to confirm you're ready, but as reassurance, if your assets are set up and ready to go, do start here on Step 2 configuration (you can create the config file anywhere as long as you paste the correct path to it once it's required), then go to Step 4.

Related

Prisma Issue of managing instances of Prisma Client actively running

I'm new to Prisma and Nodejs
I accidentally created lots of instances of Prisma Client that keep displaying the warning of
warn(prisma-client) There are already 10 instances of Prisma Client actively running.
Even I tried to delete old files and create a new Prisma, it keep showing the same warning.
I was wondering is there any way to clear the duplicated instances that already actively running?
I found a lot of INFO only about to prevent the situation occur instead of clearing it.
Node js version. : v14.18.2
NPM version. : 6.14.15
prisma : 3.7.0
#prisma/client : 3.7.0
Thank you for your help.
So the problem is that you are probably creating a new PrismaClient() every time you need to use it. The ideal would be to instantiate it once and only use that instance. In the docs they recommend it in this way
If you are in a serverless env, you can try this code as well:
import { PrismaClient } from "#prisma/client";
declare global {
namespace NodeJS {
interface Global {
prisma: PrismaClient;
}
}
}
let prisma: PrismaClient;
if (!global.prisma) {
global.prisma = new PrismaClient({
log: ["info"],
});
}
prisma = global.prisma;
export default prisma;
the problem is that you are probably creating a new PrismaClient()
you can use singleTon pattern to solve it ,(I'm use typescript here !)
import { PrismaClient } from '#prisma/client'
export class Prisma {
public static Prisma :PrismaClient ;
static getPrisma (){
//verify if prisma instance not exist
if (this.Prisma===null || !this.Prisma)
//create new one
this.Prisma=new PrismaClient()
return this.Prisma
}
}

AdonisJs Ace - E_IOC_LOOKUP_FAILED

I'm trying to load the Event system into an ace command.
public async run() {
const { default: Event } = await import('#ioc:Adonis/Core/Event')
}
However this results in the following error: Cannot resolve "Adonis/Core/Event" namespace from the IoC Container
Based on the documentation I'm doing this right: https://docs.adonisjs.com/guides/ace-commandline#top-level-imports-are-not-allowed
Could anyone please advise?
Try this commandit solve your issue.
node ace generate:manifest
Set loadApp in your command settings property to true.
Then, run the command node ace generate:manifest.

Cypress: Cannot use cy.task() to load dataset to Mongo before tests

I'm trying to use cy.taks() to load certain datasets to mongo before a test is run. But I'm getting errors. I've got a module where I export 2 functions, one from dropping a collection, and the other to load an object to a collection. Here is my cypress/plugins/index.js:
module.exports = (on, config) => {
on("task", {
"defaults:db": () => {
const {dropCollection, createUser } = require("../../lib/connectDB");
dropCollection("users");
createUser(userData)
},
});
};
Here is my /lib/connecDB.js:
export function dropCollection(collection) {
return mongoose.connection.dropCollection(collection);
}
export async function createUserInDB(userData) {
await User.create(userData);
}
So when I run the test, I'm getting:
cy.task('defaults:db') failed with the following error:
Unexpected token 'export'
Tried as well importing these function outside the index.js export, but getting same result.
I'd say it is something about export/import. The functions are exported as ES6, and imported as ES5.
I've tried to import the function the ES6 like:
import { dropCollection, createUser } from '../lib/connectDB'
And then export the plugin function also as ES6, but then I get:
Error: The plugins file is missing or invalid.
Your `pluginsFile` is set to `C:\Users\someRoute\cypress\plugins\index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.
I've also tried to import required modules outside the function like:
const globalDbUtils = require('../lib/connectDB')
And then use the functions as
globalDbUtils.dropCollection("collectionName")
globalDbUtils.createUser(userData)
But I'm getting last error. I've tried pretty much everything, I tried to import Mongoose models straight, mongo client etc...Also I tried to import just one function and return it (just copy/pasting official doc...) but cannot make it work. I researched for a couple of days getting nothing, I found there is a npm package that helps u doing this, but since cypress allows you to do this by using no more plugins, I'd like to do it with no more tools than cypress itself.
Anyone knows what I am doing wrong?
Thanks in advance!
You need to use require instead of import at the top of your file and when exporting at the bottom use
module.exports = { createUserInDB }
Instead of exporting as you are currently doing.

Getting DialogSet.add(): Invalid dialog being added when testing

I'm trying to build some tests for my bot dialogs. I'm using the same test code (and modified test data) with two different bots with the identical dialog names. As such, the test.js file is the same for both bots. However, when I try to run my tests via Mocha on the second bot, I am getting an Error: DialogSet.add(): Invalid dialog being added. message for each test. This does not happen with my first bot. I even tried replacing the dialog file in the second bot with the one from the (working) first, and I still got the same error. As such I can't find anything different between the bots. I even replaced all of the files in question (the test, the test data/conversation, and the dialog itself) with the files from the first bot and still got the same error. Lastly, all botbuilder packages and other dependencies are the same version between the bots. I'm at a loss here...anyone have any ideas?
Here is the dialog that is being called. I left out the actual dialog steps but that shouldn't be relevant to the issue since all of the Dialog add activity happens in the constructor.
const { TextPrompt, ChoicePrompt, ConfirmPrompt, ChoiceFactory, ComponentDialog, WaterfallDialog, DialogSet, DialogTurnStatus } = require('botbuilder-dialogs');
const { VistaServiceHelper } = require('../helpers/vistaServiceHelper');
const { TrackingServiceHelper } = require('../helpers/trackingServiceHelper');
const { CosmosDbStorage } = require('botbuilder-azure');
const LINE_PROMPT = 'linePrompt';
const ORDER_PROMPT = 'orderPrompt';
const CRITERIA_PROMPT = 'criteriaPrompt';
const SEARCH_CRITERIA = ['GO', 'PO'];
const WATERFALL_DIALOG = 'waterfallDialog';
const CONFIRM_PROMPT = 'confirmPrompt';
// Static texts
const escalateMessage = `Escalation message here`
const msDay = 86400000;
class viewOrderDialog extends ComponentDialog {
constructor(dialogId, userDialogStateAccessor, userState) {
super(dialogId);
this.addDialog(new ChoicePrompt(CRITERIA_PROMPT));
this.addDialog(new TextPrompt(ORDER_PROMPT));
this.addDialog(new TextPrompt(LINE_PROMPT, this.validateLineNumber));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.requestOrderNumber.bind(this),
this.selectSearchCriteria.bind(this),
this.displayLineItems.bind(this),
this.displayLineStatus.bind(this),
this.loopStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
this.integrationLog = new CosmosDbStorage({
serviceEndpoint: process.env.ACTUAL_SERVICE_ENDPOINT,
authKey: process.env.ACTUAL_AUTH_KEY,
databaseId: process.env.DATABASE,
collectionId: 'integration-logs'
});
this.queryData = {};
} // End constructor
I was able to fix this by deleting the botbuilder-testing folder inside the project's node_modules folder and rerunning npm install botbuilder-testing (even though I had already confirmed version in package.json and package-lock.json were showing latest version and had run npm install and npm update).
It appears this did stem from some sort of versioning issue and for whatever reason, only completely deleting the folder and reinstalling fixed it.
You may want to also verify the version of botbuilder inside your package.json file, because all of this packages must be at the same version
Ex:
"botbuilder": "~4.10.3",
"botbuilder-ai": "~4.10.3",
"botbuilder-dialogs": "~4.10.3",
"botbuilder-testing": "~4.10.3",
I Believe the accepted answer does not work in all cases . the correct answer would be to have the same botbuilder and botbuilder-testing versions .
I had the same problem and putting the same versions (or at least not putting a botbuilder-testing version above botbuilder worked)
Example
Here are example versions that work together :
"botbuilder": "~4.13.6",
"botbuilder-dialogs": "~4.13.6",
"botbuilder-testing": "^4.13.6",

Write to ethereum wiithout metamask

I'm trying to write some data to Ethereum Rinkeby test network without using meta mask, But while calling the method i'm getting the error below
, But my argument count is correct
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 246): Error: Invalid number of arguments to Solidity function
The node code
var Web3 = require('web3')
var contract = require("truffle-contract")
var quickBooks = require('../build/contracts/quickBooks.json')
Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send;
var provider = new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/KEY")
var quickBooksContract = contract(quickBooks);
quickBooksContract.setProvider(provider);
var writeToEthereum = async function(_json){
//console.log(_json)
var instance = await quickBooksContract.at('ADDRESS')
var result = await instance.write.call(_json,_json.txhash,_json.createdt,"1",_json.write_set[0].set,{
from : "ADDRESS"
})
console.log(result);
}
Solidity
pragma experimental ABIEncoderV2;
contract quickBooks{
struct Tx{
string txId;
string timeStamp;
string blockHash;
string payLoad;
string json;
}
mapping(string => Tx) private data;
function write(string _json,string _txId,string _timeStamp,string _blockHash,string _payLoad) public returns(bool success){
data[_txId] = Tx(_txId,_timeStamp,_blockHash,_payLoad,_json);
return true;
}
function read(string _txId)public returns(Tx){
return data[_txId];
}
}
Your call the contract function is wrong, you should pass the arguments to the function after the function name. The way you do it you are passing the arguments in the place of the call() options.
await instance.write(<params here>).call();
You can read more about this on the docs: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html
This can possibly be related to https://github.com/ethereum/web3.js/issues/1043
Check out the discussion there.
If you are using truffle try out:
Guys, Delete your build folder, then run the command.
npm run truffle migrate --reset --compile-all
I find it works best when running truffle locally to the folder rather
than globally, due to the beta and different versions getting updated
quickly recently. if you prefer the global approach try
truffle migrate --reset --compile-all
If this does not help, make sure you provide the correct data types. It might be that you are providing a string instead of an int.
If this does not help as well I will need more info on what version of web3 you are using and if you are using truffle and which version is it.

Resources