EOSJS和Scatter-无法读取未定义的属性'Symbol(Symbol.iterator)'

时间:2018-11-28 03:24:24

标签: javascript eos

每当我尝试使用Scatter传输EOS时都会出现错误。问题似乎出在eosjs中。散点图打开,我成功签名,但是交易失败,并出现以下错误。我认为这是在eosjs试图将交易推向区块链时发生的。

Uncaught (in promise) TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
    at ./node_modules/eosjs/dist/eosjs-jsonrpc.js.__values (eosjs-jsonrpc.js:42)
    at arrayToHex (eosjs-jsonrpc.js:58)
    at JsonRpc.<anonymous> (eosjs-jsonrpc.js:323)
    at step (eosjs-jsonrpc.js:36)
    at Object.next (eosjs-jsonrpc.js:17)
    at eosjs-jsonrpc.js:11
    at new Promise (<anonymous>)
    at ./node_modules/eosjs/dist/eosjs-jsonrpc.js.__awaiter (eosjs-jsonrpc.js:7)
    at JsonRpc../node_modules/eosjs/dist/eosjs-jsonrpc.js.JsonRpc.push_transaction (eosjs-jsonrpc.js:316)
    at Api.<anonymous> (eosjs-api.js:411)
    at step (eosjs-api.js:44)
    at Object.next (eosjs-api.js:25)
    at eosjs-api.js:19
    at new Promise (<anonymous>)
    at ./node_modules/eosjs/dist/eosjs-api.js.__awaiter (eosjs-api.js:15)
    at Api../node_modules/eosjs/dist/eosjs-api.js.Api.pushSignedTransaction (eosjs-api.js:409)
    at Api.<anonymous> (eosjs-api.js:399)
    at step (eosjs-api.js:44)
    at Object.next (eosjs-api.js:25)
    at fulfilled (eosjs-api.js:16)

我尝试过的事情

  • 删除并重新安装所有节点模块
  • 开发和生产环境
  • 在构造函数中初始化this.eos

这是整个文件。

import React from "react";
import { Api, JsonRpc, JsSignatureProvider } from "eosjs";
import ScatterJS from "scatterjs-core";
import ScatterEOS from "scatterjs-plugin-eosjs2"; // Use eosjs2 if your version of eosjs is > 16

// Using junglehistory here to get actions.  I tried the transaction with https://jungle2.cryptolions.io:443 and got the same error.
const endpoint = "http://junglehistory.cryptolions.io:18888"; // Jungle

const network = {
    blockchain: "eos",
    protocol: "https",
    host: "jungle2.cryptolions.io",
    port: 443,
    chainId: "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473" // Jungle
};

class EOSIOClient extends React.Component {
    constructor(contractAccount) {
        super(contractAccount);
        this.contractAccount = contractAccount;
        this.account;
        this.eos;

        ScatterJS.plugins(new ScatterEOS());

        try {
            ScatterJS.scatter.connect(this.contractAccount).then(connected => {
                if (!connected) return console.log("Issue Connecting");

                const scatter = ScatterJS.scatter;
                this.scatter = scatter;

                this.requiredFields = {
                    accounts: [network]
                };

                this.rpc = new JsonRpc(endpoint);
                window.ScatterJS = null;
            });
        } catch (error) {
            console.log(error);
        }
    }

    login = cb => {
        try {
            this.scatter.getIdentity(this.requiredFields).then(() => {
                this.account = this.scatter.identity.accounts.find(
                    x => x.blockchain === "eos"
                );

                this.eos = this.scatter.eos(network, Api, { rpc: this.rpc });
                return cb(this.account);
            });

            window.ScatterJS = null;
        } catch (error) {
            console.log(error);
        }
    };

    transaction = (action, data) => {
        return this.eos.transact(
            {
                actions: [
                    {
                        account: this.contractAccount,
                        name: action,
                        authorization: [
                            {
                                actor: this.account.name,
                                permission: this.account.authority
                            }
                        ],
                        data: {
                            ...data
                        }
                    }
                ]
            },
            {
                blocksBehind: 3,
                expireSeconds: 30
            }
        );
    };

    tokenTransfer = data => {
        return this.eos.transact(
            {
                actions: [
                    {
                        account: "eosio.token",
                        name: "transfer",
                        authorization: [
                            {
                                actor: this.account.name,
                                permission: this.account.authority
                            }
                        ],
                        data: {
                            from: this.account.name,
                            to: data.to,
                            quantity: data.quantity,
                            memo: data.memo
                        }
                    }
                ]
            },
            {
                blocksBehind: 3,
                expireSeconds: 30
            }
        );
    };

1 个答案:

答案 0 :(得分:0)

将eosjs更新到20.0.0-beta2.2解决了此问题