0

When i try to do transaction this error gets thrown no information on this so far I am using latest version of eosjs v= 21.0.2
I am reading the accounts names balance to transfer and public key from a csv Here is the code

const fs = require('fs');
const csv = require('csv-parser');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const fetch = require('node-fetch');
const { TextEncoder, TextDecoder } = require('util');

const wiloPrivateKey = "5Joa9PDtdAGTjwsnmw1DDVang9crvZAkcUVZQpH6oxASddD3w69";
const wilosigProvider = new JsSignatureProvider([wiloPrivateKey]);

const wizzPrivateKey = "5JVBshn4pEkMkYv8d4Y1KQYt7Tqo5uYwAKFtMSQJKg7RCMqLidb";
const wizzsigProvider = new JsSignatureProvider([wizzPrivateKey]);

const rpc = new JsonRpc('http://104.156.59.187:8888', { fetch });

const api = new Api({ rpc, wilosigProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const api2 = new Api({ rpc, wizzsigProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
// Function to read Csv
async function makeCsv() {
    const readable = fs.createReadStream('/home/vector/Desktop/wilo_contracts/data_retrieval/wizzRestoreCSVs/wizz1.csv')
    const pending = [];
    return new Promise((resolve, reject) => {
        readable.pipe(csv(['name', 'balance', 'key']))
            .on('data', (data) => {
                console.log(data);
                const create = async (data) => {
                    data.status = await createAccount(data)
                    return data
                }
                pending.push(create(data))
            })
            .on('end', () => {
                Promise.all(pending).then(results => resolve(results));
            });
    })
}

async function createAccount(account) {
    const result = (async () => {
        try {
            await api.transact({
                actions: [{
                    account: 'eosio',
                    name: 'newaccount',
                    authorization: [{
                        actor: 'wilonet',
                        permission: 'active',
                    }],
                    data: {
                        creator: 'wilonet',
                        name: account.name,
                        owner: {
                            threshold: 1,
                            keys: [{
                                key: account.key,
                                weight: 1
                            }],
                            accounts: [],
                            waits: []
                        },
                        active: {
                            threshold: 1,
                            keys: [{
                                key: account.key,
                                weight: 1
                            }],
                            accounts: [],
                            waits: []
                        },
                    },
                },
                {
                    account: 'eosio',
                    name: 'buyrambytes',
                    authorization: [{
                        actor: 'wilonet',
                        permission: 'active',
                    }],
                    data: {
                        payer: 'wilonet',
                        receiver: account.name,
                        bytes: 8192,
                    },
                },
                {
                    account: 'eosio',
                    name: 'delegatebw',
                    authorization: [{
                        actor: 'wilonet',
                        permission: 'active',
                    }],
                    data: {
                        from: 'wilonet',
                        receiver: account.name,
                        stake_net_quantity: '1.0000 ILO',
                        stake_cpu_quantity: '1.0000 ILO',
                        transfer: false,
                    }
                }],
            }, {
                blocksBehind: 3,
                expireSeconds: 30,
            });
            await api2.transact({
                actions: [
                    {

                        account: 'eosio.token',
                        name: 'transfer',
                        authorization: [{
                            actor: 'wizznetwork',
                            permission: 'active',
                        }],
                        data: {
                            from: 'wizznetwork',
                            to: account.name,
                            quantity: account.balance,
                            memo: 'Wizz Balance Return'
                        }
                    }
                ]
            }, {
                blocksBehind: 3,
                expireSeconds: 30,
            });
            return 'success'
        } //try ends
        catch (e) {
            console.log('\nCaught exception: ' + e);
            if (e instanceof RpcError)
                console.log(JSON.stringify(e.json, null, 2));
            return 'fail'
        }
    })();
    return result
}

async function writeFile() {
    const csvWriter = createCsvWriter({
        path: 'Wizzstatus.csv',
        header: [
            { id: 'name', title: 'Account' },
            { id: 'balance', title: 'Balance' },
            { id: 'key', title: 'PubKey' },
            { id: 'status', title: 'Result' },
        ]
    });
    let records = []
    records = await makeCsv(records)
    csvWriter.writeRecords(records)       // returns a promise
        .then(() => {
            console.log('...Done');

        });
}
writeFile();

Your Answer

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

Browse other questions tagged or ask your own question.