MetaMask - RPC Error: execution reverted. Error: cannot estimate gas - node.js

I have a
MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'}
next-dev.js?3515:25
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas", transaction={"from":"0x563925491A8B3100c329d05292c059A84165dFB7","to":"0x159bB9B4A6b7f1165141Bc927a32237a143609C9","value":{"type":"BigNumber","hex":"0x016345785d8a0000"},"data":"0xd6febde800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","accessList":null}, error={"code":-32000,"message":"execution reverted"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
at Logger.makeError (index.js?dd68:219:1)
at Logger.throwError (index.js?dd68:228:1)
at checkError (json-rpc-provider.js?8679:76:1)
at Web3Provider.eval (json-rpc-provider.js?8679:533:1)
at Generator.throw (<anonymous>)
at rejected (json-rpc-provider.js?8679:6:42)
I did everything by Clever Programmer's tutorial: https://www.youtube.com/watch?v=x3eRXeMB-4k&list=WL&ab_channel=CleverProgrammer. And now I have this error after running this piece of code:
const buyItem = async (
listingId = selectedMarketNft.id,
quantityDesired = 1,
module = marketPlaceModule
) => {
console.log(listingId, quantityDesired, module, 'david')
// yo RAZA lets goooo!!!
//yo Qazi, ok
// sure okay about to run it...
// just clicked buy now...
// still error
// where can i see the contract address of the marketplace module
// in [nftId.js]
await module
.buyoutDirectListing({listingId, quantityDesired})
.catch((error) => console.error(error))
confirmPurchase()
}

Related

Trying to run a JS script on mac terminal but keep getting NETWORK_ERROR

I am a complete noob and watching a video on ether.js. I am trying to run a script with node.js on my mac terminal but keep getting this error.
MY CODE
const address = '0xb5d85CBf7cB3EE0D56b3bB207D5Fc4B82f43F511';
const main = async () => {
const balance = await provider.getBalance(address);
console.log(`\nETH Balance of ${address} --> ${ethers.utils.formatEther(balance)} ETH\n`)
main()
RUN ERROR
/Users/mac/ethers_examples/node_modules/#ethersproject/logger/lib/index.js:199
var error = new Error(message);
^
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.3)
at Logger.makeError (/Users/mac/ethers_examples/node_modules/#ethersproject/logger/lib/index.js:199:21)
at Logger.throwError (/Users/mac/ethers_examples/node_modules/#ethersproject/logger/lib/index.js:208:20)
at JsonRpcProvider.<anonymous> (/Users/mac/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:517:54)
at step (/Users/mac/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:48:23)
at Object.throw (/Users/mac/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:29:53)
at rejected (/Users/mac/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
}

Before test runs, fails on CCI pipeline: "TypeError: Cannot read property 'createEvent' of null"

I have tried researching other topics similar to this error message ( such as from here, here, here among others. ):
TypeError: Cannot read property 'createEvent' of null
In our test suit we have a lot of mocked network calls as a single mocking layer, but there is a throw new Error('unexpected URL') handler for missing calls.
Also, I have verified all of my ReactTesting findBy queries are correctly declared with async/await syntax. Sometimes the tests work, othertimes fails.
What is really curious, is the error happens ONLY in Circle CI before any tests run, it appears, based on the error message call stack:
#!/bin/bash -eo pipefail
yarn test:ci
yarn run v1.22.11
$ jest --ci --runInBand
/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905
var evt = document.createEvent('Event');
^
TypeError: Cannot read property 'createEvent' of null
at Object.invokeGuardedCallbackDev (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905:26)
at invokeGuardedCallback (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
at flushPassiveEffectsImpl (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
at unstable_runWithPriority (/home/circleci/project/node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
at runWithPriority$1 (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
at flushPassiveEffects (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
at Object.<anonymous>.flushWork (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
at Immediate.<anonymous> (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1003:11)
at processImmediate (internal/timers.js:464:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
I have not seen this error locally, even when running the same command as my Circle CI command.
Any ideas about this, other than unhandled
Can you try this. async() await and use expect() function and also catch the execption by new Error Object.
it("Should ...", async () => {
await myFn(async () => {
// some operations
expect(await element.length).toBe(10).toThrow(new Error("something went wrong!"))
});
});
Try adding expect(something...) to the tests, like mentioned here.
You should finish your test with some sort of an assertion.

Nestjs Repository test fails with error "Received promise resolved instead of rejected"

I am writing unit tests for my backend application, I am struggling to test for a item in the database not being found, this is the code for my repository to be tested:
#EntityRepository(Collectible)
export class CollectibleRepository extends Repository<Collectible> {
async getCollectible(id: number) {
const collectible = await this.findOne(id);
if (!collectible) {
throw new NotFoundException();
}
return collectible;
}
}
And this is the code for testing, I will only show this test case.
const mockCollectible = new Collectible(
faker.lorem.sentence(),
faker.lorem.sentences(3),
faker.datatype.float(),
faker.datatype.float(),
faker.datatype.number(),
);
describe('Collectible Repository', () => {
let collectibleRepository: CollectibleRepository;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [CollectibleRepository],
}).compile();
collectibleRepository = module.get<CollectibleRepository>(
CollectibleRepository,
);
});
describe('View Collectibles', () => {
it('throws and error as the collectible is not found', async (done) => {
collectibleRepository.findOne = jest.fn().mockResolvedValue(undefined);
await expect(collectibleRepository.getCollectible(1)).rejects.toThrow(
NotFoundException,
);
done();
});
});
});
This causes the following error output:
Expected message: not "Not Found"
8 | const collectible = await this.findOne(id, { relations: ['business'] });
9 | if (!collectible) {
> 10 | throw new NotFoundException();
| ^
11 | }
12 | return collectible;
13 | }
at CollectibleRepository.getCollectibleBusiness (src/collectible/collectible.repository.ts:10:13)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:95012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:95012) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FAIL src/collectible/collectible.repository.spec.ts (8.525 s)
● Collectible Repository › View Collectibles › throws and error as the collectible is not found
expect(received).rejects.not.toThrow()
Received promise resolved instead of rejected
Resolved to value: undefined
39 | it('throws and error as the collectible is not found', async (done) => {
40 | collectibleRepository.findOne = jest.fn().mockResolvedValue(undefined);
> 41 | await expect(collectibleRepository.getCollectible(1)).rejects.not.toThrow(
| ^
42 | NotFoundException,
43 | );
44 | done();
at expect (../node_modules/expect/build/index.js:134:15)
at Object.<anonymous> (collectible/collectible.repository.spec.ts:41:13)
I tried using this repository (which was mentioned in another SO thread) with a set of examples for testing Nest.js applications, but it seems like a repository is not being directly tested.
Update: I updated my code since I was missing a await in my code (as noted by Micael Levi ), I was also calling the wrong function (lol). I am receiving the following warning:
(node:98378) UnhandledPromiseRejectionWarning: Error: expect(received).rejects.not.toThrow(expected)
Though probably I will ignore it unless it affects my CI pipeline (which I need to configure lmao)
Update 2: Warning was caused by another test (I may rest for now).
you missed the await in const collectible = this.findOne(id);
So
const collectible = await this.findOne(id);

TypeError: Cannot read property 'then' of null | discord.js

I am trying to make a message tracker and this error shows and I don't know why
Code: messagecounter.js
const db = require('quick.db');
module.exports = {
name: "msgc",
description: "Message Counter",
async run(client, message, args) {
// checking who wants to fetch it
let member = message.mentions.members.first() || message.member; // this checks if they mentioned a members
db.fetch(`messageSent_${member.id}`).then(obj => {
message.channel.send(`**Messages Sent:** \`${obj.value}\``);
});
}
}
Code: bot.js:70:42
client.commands.get(command).run(client, message, args);
Error:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'then' of null
at Object.run (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\blade\commands\messagecounter.js:13:45)
at Client.<anonymous> (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\blade\bot.js:70:42)
Any help would be appreciated
Using discord.js v12
After quickly glancing over "quick.db" I couldn't find a method called fetch defined on the db object. "get", however is defined and is perhaps what you meant to use.

What is the Dockerfile to use node:12-alpine with puppeteer#1.19?

Since I faced puppeteer#1.13 error when printing pdf with lots of photos(at least need to renew the lock):
when running in Dev, there was exception:
(node:17) UnhandledPromiseRejectionWarning: Error: Page crashed!
at Page._onTargetCrashed (/usr/src/app/node_modules/puppeteer/lib/Page.js:176:24)
So I would like to use latest version of puppeteer#1.19. However, when I changed to use that, there is error :
Line239: await page.pdf({
path: TEMP_DIR + filename,
format: 'A4',
printBackground: true
});
printPdf() Error
Error: Protocol error (IO.read): Invalid parameters handle: string value expected
at /usr/src/app/node_modules/puppeteer/lib/Connection.js:183:56
at new Promise ()
at CDPSession.send (/usr/src/app/node_modules/puppeteer/lib/Connection.js:182:12)
at Function.readProtocolStream (/usr/src/app/node_modules/puppeteer/lib/helper.js:241:37)
at async Page.pdf (/usr/src/app/node_modules/puppeteer/lib/Page.js:988:12)
at async printPdf (/usr/src/app/puppeteer.js:239:9)
at async /usr/src/app/puppeteer.js:129:21
-- ASYNC --
at Page. (/usr/src/app/node_modules/puppeteer/lib/helper.js:111:15)
at printPdf (/usr/src/app/puppeteer.js:239:20)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async /usr/src/app/puppeteer.js:129:21 {
message: 'Protocol error (IO.read): Invalid parameters handle: string value expected'
}
How can I prepare Dockerfile to support puppeteer#1.19 or solve this error? Thanks.

Resources