I have no idea where am i making mistake? please help.
const express = require('express');
const path= require('path');
const app =express();
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const fetch = require('node-fetch');
const defaultPrivateKey = "exsisting account private key"; // bob
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc('http://jungle2.cryptolions.io:80', { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
//Body parser Middleware
app.use(express.json());
app.use(express.urlencoded({extended:false}));
app.get('/', function (req, res) {
res.send('hello world')
})
//
app.post('/', (req,res) => {
// res.send(req.body.new_account_name);
var existingaccount = 'microfinanc1'
var mynewaccount=req.body.new_account_name;
var pubkey=req.body.publickey;
console.log('Is it working');
console.log(pubkey);
console.log(newaccount);
result (async ()=> {
await api.transact({
actions: [{
account:'eosio' ,
name: 'newaccount',
authorization: [{
actor: existingaccount,
permission: 'active',
}],
data: {
creator: existingaccount,
name: mynewaccount,
owner: {
threshold: 1,
keys: [{
key: pubkey,
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: pubkey,
weight: 1
}],
accounts: [],
waits: []
},
},
},
{
account: 'eosio',
name: 'buyrambytes',
authorization: [{
actor: existingaccount,
permission: 'active',
}],
data: {
payer: existingaccount,
receiver: mynewaccount,
bytes: 5000,
},
},
{
account: 'eosio',
name: 'delegatebw',
authorization: [{
actor: existingaccount,
permission: 'active',
}],
data: {
from: existingaccount,
receiver: mynewaccount,
stake_net_quantity: '1.0000 EOS',
stake_cpu_quantity: '1.0000 EOS',
transfer: false,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
}).then(function (result) {
console.log("here??");
console.log(result);
})
// .catch(function (error) {
// if (error) {
// console.log(error);
// }
// })
})
result();
});
const port = process.env.port || 5000;
app.listen(port ,()=> console.log(`server got started on port ${port} `));
Error
ReferenceError: newaccount is not defined
at app.post (/home/guru/nodejs/express js/index.js:48:15)