eosjs的httpEndPoint不变

时间:2018-07-29 04:59:55

标签: eos

我测试了一些eosjs api。

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

这是我的代码。

//////////////////////////////////     从'eosjs'导入*作为Eos

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;

我从下面的react组件中调用此方法。

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。

如何解决这个问题?

1 个答案:

答案 0 :(得分: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);
};