2

每当我尝试使用 Scatter 传输 EOS 时,都会出现错误。问题似乎出在 eosjs 中。Scatter 打开并且我成功签名,但随后交易失败并出现以下错误。我认为它正在发生,因为 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
            }
        );
    };
4

1 回答 1

0

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

于 2018-11-28T21:11:19.917 回答