Invalid JSON RPC response: undefined - javascript

I'm trying to create an Ethereum account through Node.js. This is my code:
export async function createNewAccount() {
var web3Instance = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
return web3Instance.eth.accounts.create();
}
But I'm getting the following error (from 'create' function):
Invalid JSON RPC response: undefined
I have installed web3.js in my project.
What other step have I missed?
BTW opening the browser on address http://localhost:8545 returns 404. Is there anything I need to install in order to make it work? Is that the testrpc?
Notice that I want to work against the real blockchain, not a test one.

Web3.js is only a javascript interface that can deal with a real node, in order to conduct RPC requests you must have an ethereum node running this can be either
TestRPC , Parity , Geth. additionally, since you are pointing to localhost you will need to run it on your own
The easiest for you to test with will be testRPC install and run it will. By default give you 10 accounts. in order to create a new account with testRPC you will need to run it with --unlock option

Related

How to get SubtleCrypto work with testcafe?

I am generating SHA256 using SubtleCrypt Web API on client-side as following:
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
Everything works fine except for when I execute tests via testcafe. The captured console error says TypeError: Cannot read properties of undefined (reading 'digest') meaning crypto.subtle is undefined.
I know that SubtleCrypto is available only in secure contexts which also includes localhost and I am using localhost to run my end-to-end testcafe tests.
What am I doing wrong?
You need to run TestCafe over HTTPS protocol. See more information in the following help topic: test-https-websites.

× Error: Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: undefined React.js

I just clone smart contract react application in VS code and installed node modules. When i try to npm start, it gave me the error " Error: Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: undefined React.js".
How can i solve this problem? Thanks
According to the Alchemy documentation,
using websockets with the web3-alchemy sdk requires setting up your web3 object with a websocket URL, like this:
const { createAlchemyWeb3 } = require("#alch/alchemy-web3");
const web3 = createAlchemyWeb3("wss://eth-mainnet.ws.alchemyapi.io/ws/<api-key>");
when it is set up correctly, you should be able to make a call, for example:
web3.eth.getBlockNumber().then(console.log); // -> 7946893
The error you are seeing is due to an incorrect argument undefined React.js being passed into the alchemy web3 instantiation, basically:
const web3 = createAlchemyWeb3( undefined React.js ); // the error is here
You need to figure out why there is an undefined React.js showing up, and once you fix that error, your app should be able to load!
Not exactly sure but check your package.json file and see the version of react-scripts. If it defines an older version, try updating to the latest with :
npm uninstall react-scripts or yarn remove react-scripts
and re-install using
yarn add react-scripts or npm add react-scripts.
So in my case the problem was that in the code where you call for the json file from artifacts has to be named properly because in my case the name of the file was different so make sure that is not the case with you.

How to Send Money Dogecoin With NodeJS?

I'm learning to make a simple Dogecoin wallet terminal for personal use. I managed to generate a private key and public address (using coinkey). And success check balance Dogecoin (using API Dogechain).
But, I'm still confused about sending Dogecoin from the private key that I generated. Is there a NodeJS module that can be used to send Dogecoin from a private key? Or maybe anyone has an example?
You'll need a running instance of dogecoind to connect with. If you're running Debian/Ubuntu, this worked for me: http://www.dogeco.in/wiki/index.php/Dogecoind
Then, install the node-dogecoin NPM package. (https://github.com/countable/node-dogecoin)
npm install node-dogecoin
var dogecoin = require('node-dogecoin')()
dogecoin
.auth('MyUserName', 'mypassword')
.getNewAddress()
.getBalance()
You could use node - dogecoin. is a simple wrapper for dogecoin wallet (and i think that is compatible with all Litecoin-compatible wallet, but not tested yet).
In this way you can generate private key, check balance, send coins and so on within a unique nodejs module

Meteor - Meteor.Collection.get not defined in production

I'm trying to use Meteor.Collection.get(collection_name) (server side only) in production, it works well in development ; but as soon as I try to build my app with meteor --production, meteor throw
TypeError: Meteor.Collection.get is not a function
I suppose that Meteor.Collection.get was only made for debugging purposes (I can't find anything about it in the official documentation). Any idea how I can use it in production ?
I am not sure, where Meteor.Collection.get comes from in your code but I know the very reliable and long time battle proof dburles:mongo-collection-instances which allows you to retrieve a Mongo.Collection via it's name.
Add the package:
meteor add dburles:mongo-collection-instances
Create a collection:
// server/client
export const MyDocs = new Mongo.Collection('myDocs')
Get the collection:
// anywhere else
const MyDocs = Mongo.Collection.get('myDocs')
It works on the server and the client and runs fine in production.
Documentation: https://github.com/dburles/mongo-collection-instances
Edit: A note on --production
This flag is only there to simulate production minifaction. See the important message here in the docs: https://guide.meteor.com/deployment.html#never-use-production-flag
You should always use meteor build to build a production node app. More to read here: https://guide.meteor.com/deployment.html#custom-deployment

Unable to Read Cookie values from Newman - Jenkins CI

Calling an API and obtaining the Cookie from response body is made possible through Interceptor in Postman.
Did it through this way: https://www.linkedin.com/pulse/how-read-cookie-value-postman-request-chaining-ishan-girdhar-oscp
But if I try to implement the same from Newman command line, It gives me an error, since there was no interceptor involved in CI (POSTMAN + JENKINS)
Tried to go through this link but It didn't help a lot: https://github.com/postmanlabs/newman/issues/242
Please suggest me a way to read cookies while running through Newman!
Many Thanks!
Use newman as Node JS module instead of from the command line.
The cookies are available in the object sent into the "request" event.
const newman = require('newman');
newman.run(options,callback)
.on('request',function(err,args) {
console.log(args.response.cookie);
})

Categories