0

我测试了一些eosjs api。

但是,由于一些问题,我被卡住了。

这是我的代码。

//////////////////////////// import * as Eos from 'eosjs'

class EOSService {
    constructor() {
        this.eos = Eos({
            httpEndPoint : 'https://eu1.eosdac.io:443',
            chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
        })
    }

    fetchTransactionData(txid, callback) {
        this.eos.getTransaction(txid)
        .then( (result) => {
            callback(result)
        })
    }

    fetchAccountData(accountName, callback) {
        this.eos.getAccount(accountName)
        .then( (result) => {
            callback(result)
        })
    }
}

export default EOSService;

我从下面的反应组件中调用这个方法。

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import EOSService from 'services/EOSService'

class AccountPage extends Component {

    componentDidMount() {
        let accountName = this.props.match.params.accountName;

        (new EOSService()).fetchAccountData(accountName, (result) => {
            console.log(result)
        })
    }

    render() {
        return(
            <div>AccountPage</div>
        );
    }
}
AccountPage.propTypes = propTypes;
AccountPage.defaultProps = defaultProps;
export default AccountPage;

但是,我遇到这样的错误。=> POST http://127.0.0.1:8888/v1/chain/get_account 0 ()

也就是说,我想从BP的httpEndPoint询问数据,但是eosjs调用的是127.0.0.1:8888。

如何解决这个问题?

4

1 回答 1

0

概括

您必须使用httpEndpoint,而不是httpEndPoint

检查以下:

<html>
<head>
  <meta charset="utf-8">

  <script src="https://cdn.jsdelivr.net/npm/eosjs@16.0.0/lib/eos.min.js"
    integrity="sha512-vNyLnOEb7uFmEtVbLnyZQ9/k4zckM2Vu3jJOKq6XfWEVZG0yKcjDExVN4EQ7e3F+rePWRncMolI2xFi/3qo62A=="
    crossorigin="anonymous"></script>

  <script>
  eos = Eos({
    httpEndpoint: 'https://eu1.eosdac.io:443',
    chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
    verbose: true
  })
  </script>
</head>
<body>
  See console object: Eos
</body>
</html>

如果您使用httpEndPoint,默认情况下会设置配置。检查此eos.js代码:

var Eos = function Eos() {
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  config = Object.assign({}, {
    httpEndpoint: 'http://127.0.0.1:8888',
    debug: false,
    verbose: false,
    broadcast: true,
    sign: true
  }, config);

  var defaultLogger = {
    log: config.verbose ? console.log : null,
    error: console.error
  };
  config.logger = Object.assign({}, defaultLogger, config.logger);

  return createEos(config);
};
于 2018-07-30T05:30:15.520 回答