0

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)

  • What error you get ? – Abdul Manan Nov 28 '19 at 11:34
  • I have updated the question with what error im getting please have a look @AbdulManan – guruprakash gupta Nov 28 '19 at 11:45
  • where is newaccount defined – Abdul Manan Nov 28 '19 at 11:55
  • I have not defined it any where,but wherever in action new account name is asked,have i given mynewaccount string there and sending its value from postman, and im getting the value which im sending from post man, its not coming null i have checked it – guruprakash gupta Nov 28 '19 at 11:59
  • there is a problem with the data you send from postman try console.log(req.body) and see what it console. Also check it with static value does the code works if you pass static data – Abdul Manan Nov 28 '19 at 12:01
0

You have

console.log(newaccount)

which is not defined anywhere as a variable. This is a js typo instead of EOS.

Replace it with

console.log(mynewaccount)
| improve this answer | |
  • I did it already, thank you for looking into – guruprakash gupta Nov 29 '19 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.