EOSIO / eosjs

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

eosjs 7.1.5 fail to initial Localnet #48

Closed Joelone closed 6 years ago

Joelone commented 6 years ago

eosio version: dawn-v3.0.0 (d9ad8ee) eosjs version: 7.1.5 (a148dc8)

Test code:

Eos = require('../src') //Eos = require('eosjs')
eos = Eos.Localnet() // eos = Eos.Testnet() // testnet at eos.io
eos.getBlock()

Error message:

$ node app/test.js 
/home/joel/eosjs/src/structs.js:117
  const staticVariant = baseTypes.static_variant([
                                  ^

TypeError: baseTypes.static_variant is not a function
    at PublicKeyType (/home/joel/eosjs/src/structs.js:117:35)
    at createType (/home/joel/eosjs/node_modules/fcbuffer/lib/types.js:161:14)
    at customTypes.(anonymous function) (/home/joel/eosjs/node_modules/fcbuffer/lib/types.js:132:20)
    at getTypeOrStruct (/home/joel/eosjs/node_modules/fcbuffer/lib/fcbuffer.js:160:13)
    at create (/home/joel/eosjs/node_modules/fcbuffer/lib/fcbuffer.js:198:16)
    at module.exports (/home/joel/eosjs/node_modules/fcbuffer/lib/index.js:51:17)
    at module.exports (/home/joel/eosjs/src/structs.js:74:58)
    at createEos (/home/joel/eosjs/src/index.js:76:50)
    at Object.Localnet (/home/joel/eosjs/src/index.js:52:12)
    at Object.<anonymous> (/home/joel/eosjs/app/test.js:2:11)
navcsdev commented 6 years ago

@Joelone I check again and I see it is success 👍

Test code:

  keyProvider: ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'], // WIF string or array of keys..
  httpEndpoint: 'http://127.0.0.1:8888',
  expireInSeconds: 60
};

const eos = Eos.Localnet(config);

console.log(eos.getBlock());

Result:


[nodemon] starting `node -r dotenv/config -r babel-register src/index.js`
[nodemon] restarting due to changes...
[nodemon] starting `node -r dotenv/config -r babel-register src/index.js`
USAGE
getBlock - Fetch a block from the blockchain.

PARAMETERS
{
  "block_num_or_id": "string"
}

RETURNS
{
  "previous": "uint32",
  "timestamp": "time",
  "transaction_merkle_root": "uint32",
  "producer": "uint16",
  "producer_changes": "map<account_name, account_name>[]",
  "producer_signature": "signature",
  "cycles": "thread[]",
  "id": "fixed_bytes33",
  "block_num": "uint32",
  "ref_block_prefix": "uint32"
}```
Joelone commented 6 years ago

Strange, I still see the same error with your code. Is it because of eosjs only support docker, and I built EOS 3.0 release from source?

app/test.js

Eos = require('../src') //Eos = require('eosjs')
config = {
  keyProvider: ['5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'], // WIF string or array of keys..
  httpEndpoint: 'http://127.0.0.1:8888',
  expireInSeconds: 60
};

const eos = Eos.Localnet(config);

console.log(eos.getBlock());

cleos output

$ cleos get info
{
  "server_version": "d9ad8eec",
  "head_block_num": 59221,
  "last_irreversible_block_num": 59220,
  "head_block_id": "0000e755b775186a91e8db5926181c6584b0fcbed3100ca473e4597fac7b6b20",
  "head_block_time": "2018-04-10T03:45:11",
  "head_block_producer": "eosio"
}

result

$ node app/test.js 
/home/joel/eosjs/src/structs.js:117
  const staticVariant = baseTypes.static_variant([
                                  ^

TypeError: baseTypes.static_variant is not a function
    at PublicKeyType (/home/joel/eosjs/src/structs.js:117:35)
    at createType (/home/joel/eosjs/node_modules/fcbuffer/lib/types.js:161:14)
    at customTypes.(anonymous function) (/home/joel/eosjs/node_modules/fcbuffer/lib/types.js:132:20)
    at getTypeOrStruct (/home/joel/eosjs/node_modules/fcbuffer/lib/fcbuffer.js:160:13)
    at create (/home/joel/eosjs/node_modules/fcbuffer/lib/fcbuffer.js:198:16)
    at module.exports (/home/joel/eosjs/node_modules/fcbuffer/lib/index.js:51:17)
    at module.exports (/home/joel/eosjs/src/structs.js:74:58)
    at createEos (/home/joel/eosjs/src/index.js:76:50)
    at Object.Localnet (/home/joel/eosjs/src/index.js:52:12)
    at Object.<anonymous> (/home/joel/eosjs/app/test.js:9:17
navcsdev commented 6 years ago

@Joelone I am using build on MacOS 😄

Joelone commented 6 years ago

@navcsdev I'm using ubuntu 16.04, but I think it shouldn't be matter for node.js

jcalfee commented 6 years ago

Is eosjs using the correct fcbuffer version like this:

npm ls fcbuffer
eosjs@7.1.5 /home/jcalfee/eosjs/eosjs
└── fcbuffer@2.1.4 
Joelone commented 6 years ago

My local repo messed up.It works now. Thanks @jcalfee