'trx project, cannot save to file after creating wallet in nodejs
I am using trx to create a wallet, the code will send a request to create a wallet and return the result, the result contains the private key and wallet address, but I can't write the result to the file
code:
'use strict';
var argv = process.argv.slice(2);
var fs = require('fs');
const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "your privateKey ";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
async function main() {
try{
const wallet = await tronWeb.createAccount();
await fs.writeFile('./try4.txt', wallet, { 'flag': 'a' }, function(err) {if (err) {throw err;}});
console.log(wallet);
} catch(error) {
console.log(JSON.stringify({result: 1, detail: error.message}));
}
}
main().then(() => {
process.exit()
})
.catch((err) => {
process.exit()
});
I tried adding code on line 16 to save the result to a file, but the file is created successfully but has no content
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
