Im using the javascript version of web3 and want to import a private key from a Web3 Secret Storage Definition file (old wiki: Passphrase protected key store spec
). According to the docs there is a decrypt and encrypt funtion:
keystoreJsonV3 = web3.eth.accounts.encrypt(privateKey, password);
privateKey = web3.eth.accounts.decrypt(keystoreJsonV3, password);
But I get an 'Uncaught TypeError: web3.eth.accounts.decrypt is not a function'. What is wrong? Is the docs wrong or is my web3.js the wrong version or something similar? How do I encrypt/decrypt keystore files.
I built my web3.js file from this source
git clone -b develop https://github.com/ethereum/web3.js.git
Those functions are not implemented yet. The functions you relate to are mostly described in the 1.0.0 version of web3 which has not been release yet.
Right now, web3.eth.accounts just retrieves an array of available accounts loaded from testrpc/ganache-cli/geth instance running on your machine.
Related
I'm using back4app as backend service to deploy my app, developed in React Native ans JS. I'm testing how to use the 'Cloud Code Functions' of back4app right now...
As I'm a beginner in back4app, I found a problem while using their guide. I'm facing this message error: 'async functions' is only available in ES8 (use 'esversion: 8').:
Back4app Side:
import Parse from 'parse/react-native.js';
import AsyncStorage from '#react-native-async-storage/async-storage';
//Initializing the SDK
Parse.setAsyncStorage(AsyncStorage);
//Paste below the Back4App Application ID AND the JavaScript KEY
Parse.initialize('YOUR_APPLICATION_ID_HERE', 'YOUR_JAVASCRIPT_KEY_HERE');
//Point to Back4App Parse API address
Parse.serverURL = 'https://parseapi.back4app.com/';
//This is a hello function and will log a message on the console
Parse.Cloud.define("hello", async (request) => {
console.log("Hello from Cloud Code!");
return "Hello from Cloud Code!";
});
my app:
const helloFunction = await Parse.Cloud.run("hello");
I know the problem comes from the asynchronous function, but I can't find any solution. What am I doing wrong?
When using the cloud code, you do not need to do any kind of initialization as it is already done on the Back4app servers.
So in your main.js file please remove:
The import statements. Lines 2 and 3.
The Parse initialization. The lines 6,8, and 10.
To really answer the question, the error message is a false positive! Probably the online editor is not configured right, so it shows these warnings accidentally...
Just as the guide tells you, you can use the async keyword if you got a running 3.x Parse Server. It should be safe to use this, as per default Parse Server 4.x is used (the server can be changed via App Settings > Server Settings > Manage Parse Server).
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
I would like to send data via Websocket from an VSCode extension. Is there a builtin websocket facility or should I import the package "ws" or else?
used ws package, which sadly is not in ES6 module format but otherwise does its job.
You can use the ws package, here is an example from the official samples repository: https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-log-streaming-sample/client/src/extension.ts
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
I am writing a Firefox extension and am looking for a way to export the private key from an installed certificate.
This would be replacing the previous process of saving a backup PKCS12 .p12 file, then running using: "openssl pkcs12 -nocert -in backup.p12 -out userkey.pem"
Thanks!
EDIT: I can now save a PKCS12 backup using the XPCOM API, I can extract the Certificate, but am still looking for a way to extract the private key (see the openssl command above). This needs to be cross platform...
If the point is simply avoiding to export the private key manually then you can use pk12util tool which is part of NSS. You can export the certificate like this:
pk12util -o backup.p12 -n certificate_name -d /firefox/profile/dir
That's a lot easier than doing the same thing from an extension. From what I know, NSS explicitly doesn't allow storing the private key unencrypted in the PEM format so you would still need OpenSSL for that.
I have given up doing this. Instead I'm writing a python CGI script and sending the certificate and keys over an SSL connection to an Apache server.