EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

TypeError: __WEBPACK_IMPORTED_MODULE_1_eosjs__.Rpc is undefined #405

Closed feekayo closed 6 years ago

feekayo commented 6 years ago

Version of EOSJS ^20.0.0-beta2

Describe the bug I keep getting this error on react everytime I try to initiate a transaction witth EOSJS

To Reproduce

import {Api, Rpc, SignatureProvider} from 'eosjs'
import  shajs from 'sha.js'

//httpEndpoint
const httpEndpoint = "http://127.0.0.1:8888";
const ContractName = "cx";

//main action call to blockchain
async function takeAction(action, dataValue) {
  const privateKey = localStorage.getItem("KEY");
  const rpc = new Rpc.JsonRpc();
  const signatureProvider = new SignatureProvider([privateKey]);
  const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

  // Main call to blockchain after setting action, account_name and data
  try {
    const resultWithConfig = await api.transact({
      actions: [{
        account: ContractName,
        name: action,
        authorization: [{
          actor: localStorage.getItem("USERNAME"),
          permission: 'active'
        }],
        data: dataValue,
      }]
    }, {
      blocksBehind: 3,
      expireSeconds: 30,
    });
    return resultWithConfig;
  } catch (err) {
    throw(err)
  }
}

Expected behavior I'm really new to eosjs and would really love to get past this asap

c0d3ster commented 6 years ago

Hello feekayo,

We have made a few breaking changes moving from beta1->beta2, which have been outlined in the PR here along with appropriate updates to the README. Included in those changes is a refactor of the JsonRpc and JsSignatureProvider classes and how they're imported, so please update your code according to the new documentation and let us know if you have any further issues. We will also be doing some release notes outlining these changes today in order to minimize any confusion on the changes from beta1->beta2.

iKest commented 6 years ago

no Rpc., just jsonRpc. or use import * as Eos from 'eosjs'

iKest commented 6 years ago

no Rpc., just jsonRpc. or use import * as Eos from 'eosjs'

c0d3ster commented 6 years ago

@iKest actually, you won't have to use JsonRpc. syntax anymore either. The interfaces have been pulled out of the eosjs_jsonrpc file now, so the syntax is now simply const rpc = new JsonRpc(httpEndpoint). The second issue for @feekayo is he must import the signature provider as JsSignatureProvider, but this is also outlined in our README and PR notes.

feekayo commented 6 years ago

Thanks for your assistance. You guys are doing an exceptional job...

I've refactored my code.. Now I'm getting an error: fetching the abi (internal service error) for my smart contract. Its progress I guess...

On Mon, Oct 22, 2018, 16:29 Cody Douglass notifications@github.com wrote:

@iKest https://github.com/iKest actually, you won't have to use JsonRpc. syntax anymore either. The interfaces have been pulled out of the eosjs_jsonrpc file now, so the syntax is now simply const rpc = new JsonRpc(httpEndpoint). The second issue for @feekayo https://github.com/feekayo is he must import the signature provider as JsSignatureProvider, but this is also outlined in our README and PR notes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EOSIO/eosjs/issues/405#issuecomment-431869140, or mute the thread https://github.com/notifications/unsubscribe-auth/APh8BrLngg2H1pxO-AkNj3fA4ua9JNnVks5uneRLgaJpZM4Xyz2Y .

c0d3ster commented 6 years ago

Thanks, happy to help eager developers out! Many of the errors from the chain are obfuscated to "Internal Service Errors" for security purposes as of right now, but since you are running a local node you should be able to see the specifics of that error message in the terminal running your local node. Without seeing the updated code, I can't say for sure what the error might be, but there's two things that come to mind right off the bat:

  1. Ensure you are using the correct httpEndpoint when intializing JsonRpc because this endpoint will be called upon to retrieve the abis
  2. Ensure your transaction is not malformed and the contract actually exists on your local chain, the contractName and action need to reference a contract you've created when initializing your chain (i.e. account: "eosio.token", name: "transfer") here's a reference for these contracts.
feekayo commented 6 years ago

I have no access to the github interface for updating this issue. Let me see if you can help me out from here..

Attached are screenshots of me successfully publishing the contract on the blockchain and the error I get, and below is my code

const eosjs = require('eosjs');

// Main action call to blockchain
async function takeAction(action, dataValue) {                    // node
only; not needed in browsers
  const { TextDecoder, TextEncoder } = require('text-encoding');  // node,
IE11 and IE Edge Browsers
  const defaultPrivateKey = localStorage.getItem("KEY");
  const signatureProvider = new
eosjs.JsSignatureProvider([defaultPrivateKey]);
  const rpc = new eosjs.JsonRpc('http://127.0.0.1:8888', {});
  const api = new eosjs.Api({ rpc, signatureProvider, textDecoder: new
TextDecoder, textEncoder: new TextEncoder });

  // Main call to blockchain after setting action, account_name and data
  try {
    const resultWithConfig = await api.transact({
      actions: [{
        account: "cx",
        name: action,
        authorization: [{
          actor: localStorage.getItem("USERNAME"),
          permission: 'active',
        }],
        data: dataValue,
      }]
    }, {
      blocksBehind: 3,
      expireSeconds: 30,
    });
    return resultWithConfig;

    console.log(resultWithConfig);
  } catch (err) {
    console.log(err);
    throw(err)
  }
}

Thanks in anticipation of your assistance in resolving this issue

On Mon, Oct 22, 2018 at 6:34 PM Cody Douglass notifications@github.com wrote:

Thanks, happy to help eager developers out! Many of the errors from the chain are obfuscated to "Internal Service Errors" for security purposes as of right now, but since you are running a local node you should be able to see the specifics of that error message in the terminal running your local node. Without seeing the updated code, I can't say for sure what the error might be, but there's two things that come to mind right off the bat:

  1. Ensure you are using the correct httpEndpoint when intializing JsonRpc because this endpoint will be called upon to retrieve the abis
  2. Ensure your transaction is not malformed and the contract actually exists on your local chain, the contractName and action need to reference a contract you've created when initializing your chain (i.e. account: "eosio.token", name: "transfer") here's https://github.com/EOSIO/eosio.contracts a reference for these contracts.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EOSIO/eosjs/issues/405#issuecomment-431908033, or mute the thread https://github.com/notifications/unsubscribe-auth/APh8BlhCK17850JCPQGm_QO8LnqF1I0nks5ungHAgaJpZM4Xyz2Y .

c0d3ster commented 6 years ago

@feekayo I'm not sure if this is your issue, but the second parameter for the JsonRpc constructor should simply be omitted in the browser (or set to null) or if you are calling this from node you need to import fetch (const fetch = require('node-fetch');). You're also missing the () on the constructor for the TextEncoder and decoder (also only necessary if you're calling from a node context). I can't see the screenshots you're talking about but you should also ensure that the cx::action exists under the cx account after fixing those other two things.

feekayo commented 6 years ago

screenshot from 2018-10-22 14-57-51 This is me pushing the contract to my local node

screenshot from 2018-10-22 14-58-25 this is the error log on my client browswer

screenshot from 2018-10-24 08-27-57 This is the network trace on mozilla..

screenshot from 2018-10-24 08-33-40 Here's ther error on the blockchain everytime I initiate a query on the frontend

I know I am definitely doing something wrong... I have made the updates you asked for in my code.. Still getting the same error.

Thanks for your assistance

iKest commented 6 years ago

catch the error with: catch (e) { console.log('\nCaught exception: ' + e); if (e instanceof RpcError) console.log(JSON.stringify(e.json, null, 2); }

for more error information

feekayo commented 6 years ago

screenshot from 2018-10-24 09-16-04

Here's what I got

iKest commented 6 years ago

hmmm. simple rpc.get_abi('cx') work?

feekayo commented 6 years ago

screenshot from 2018-10-24 09-47-52

The error on my local node from the get_abi function

screenshot from 2018-10-24 09-48-42

The error on my log from get_abi function

I unlocked my wallets before carrying out the actions