1

when switching from Dawn 4.0 / eosjs 11.0.01 to Dawn 4.2 / eosjs 13.1.0, I bumped into the following problem:

const eosioToken = 'eosio.token'

try {
    const eosioTokenClientAccount = await eos.newaccount({
        creator: 'eosio',
        name: eosioToken,
        owner: eosioTokenClientPublic,
        active: eosioTokenClientPublic,
        recovery: 'eosio',
        deposit: '0 EOS'});

    const eosioTokenClientContractPath = eosContractsPath + '/eosio.token/eosio.token';
    const wast = fs.readFileSync(eosioTokenClientContractPath + '.wast')
    const abi = fs.readFileSync(eosioTokenClientContractPath + '.abi')    

    try {
        const res_code = await  eos.setcode(eosioToken, 0, 0, wast);
        const res_abi = await eos.setabi(eosioToken, JSON.parse(abi));
    } catch(e) {
        console.log(e);
    }

    // let eosioTokenAccount = await eos.getAccount(eosioToken);
    let eosioTokenContract = await eos.contract(eosioToken);
} catch(err) {
    console.log(err);
}

The problem is that when calling eos.contract(), I have the following exception:

null: api error =>
null: Object {message: "read datastream of length 14 over by -12", file: "datastream.cpp", line_number: 6, method: "throw_datastream_range_error"}
null: http://127.0.0.1:8888/v1/chain/get_code {"account_name":"eosio.token"}
null: Error: {"code":500,"message":"Internal Service Error","error":{"code":8,"name":"out_of_range_exception","what":"Out of Range","details":[{"message":"read datastream of length 14 over by -12","file":"datastream.cpp","line_number":6,"method":"throw_datastream_range_error"},{"message":"Error unpacking field version","file":"raw.hpp","line_number":368,"method":"operator()"},{"message":"error unpacking eosio::chain::abi_def","file":"raw.hpp","line_number":616,"method":"unpack"}]}}
null: Error: {"code":500,"message":"Internal Service Error","error":{"code":8,"name":"out_of_range_exception","what":"Out of Range","details":[{"message":"read datastream of length 14 over by -12","file":"datastream.cpp","line_number":6,"method":"throw_datastream_range_error"},{"message":"Error unpacking field version","file":"raw.hpp","line_number":368,"method":"operator()"},{"message":"error unpacking eosio::chain::abi_def","file":"raw.hpp","line_number":616,"method":"unpack"}]}}

It is important to notice that this code works perfectly on Dawn 4.0 / eosjs 11.0.1

Thank you in advance

Pierre

  • Apparently the problem is already reported in github.com/EOSIO/eos/issues/3159 – Pierre Pontevia Jun 2 '18 at 4:12
  • The "datastream" error was a bug fixed in 13.1.0, double check your install (try Eos.version) to make sure you have that version (github.com/EOSIO/eosjs/issues/110). .. Other things are: Your code looks a bit out of date.. Newaccount does not have recovery or deposit and may need a buyrambytes and deleggatebw in the same transaction. Also if your sending in "wast" and not "wasm" you need binaryen (see the README).. – slim2k Jun 3 '18 at 3:04
  • 1
    Hi there, I confirm the bug is gone with eosjs 14.1.0 I combined with eos 1.0.1. Point taken regarding the "out of date" code. – Pierre Pontevia Jun 4 '18 at 4:13
  • Pierre, only a little bit out of date .. lol .. seems like things change every day, they change on me too... – slim2k Jun 5 '18 at 13:51
  • 1
    I'm voting to close this question as off-topic because it is about outdated pre-launch code. – Don P Jan 17 '19 at 15:40

Browse other questions tagged or ask your own question.