0

I test some eosjs apis.

But, I am stucked because of some problems.

This is my code.

///////////////////////////////// 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;

I call this methods from react component like below.

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;

But, I encounter error like this. => POST http://127.0.0.1:8888/v1/chain/get_account 0 ()

In other words, I want to ask data from BP's httpEndPoint, but eosjs called 127.0.0.1:8888.

How to solve this?

1 Answer 1

0

Summary

You have to use httpEndpoint, not httpEndPoint.

Check below:

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

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/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>

If you use httpEndPoint, config will be set by default. Check this eos.js code:

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);
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.