EOSIO / eosjs

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

eosjs relies on eosio.token for custom currencies #200

Closed robertkowalski closed 6 years ago

robertkowalski commented 6 years ago

When I deploy the eosio.token contract under a different account, the eosjs lib still tries to connect to eosio.token.

I have a custom contract which uses a token which I create and issue from a different account than eosio.token. I used cleos set contract testcontract build/contracts/eosio.token/ for it. (note the use of the accountname testcontract)

My setup is a blank node, with just the custom contract and the eosio.token contract under a differently named account.

Now when using eosjs it seems to pick up eosio.token somewhere:

    eos.contract('organiccandy').then((contract) => {
      const args = order.serialize()
      contract.orderCandy(args, { authorization: 'testuser1234@active' })
    })
api > http://127.0.0.1:8888/v1/chain/get_currency_stats {"code":"eosio.token","symbol":"CANDY"}
api error => { message: 'Fail to retrieve account for eosio.token',
  file: 'chain_plugin.cpp',
  line_number: 637,
  method: 'get_abi' } http://127.0.0.1:8888/v1/chain/get_currency_stats {"code":"eosio.token","symbol":"CANDY"}

When I upload eosio.token as eosio.token eosjs does not error.

The problem just happens with the JS lib, CLI is working.

I found that the problem probably is here, eosio.token is used value for account, even though my token comes from another account (namely testcontract in my example)

https://github.com/EOSIO/eosjs/blob/324ceeb7fbd21ebd1d204a1ef086a041aeebc54e/src/write-api.js#L167
jcalfee commented 6 years ago

Was a bug .. just fixed it in eosjs@15 .. The side-effect is asset values need to be padded (1.0000 instead of 1 for example). I will encourage implementations to use UDecimalPad to improve UX:

https://github.com/EOSIO/eosjs/blob/master/docs/format.md#UDecimalPad

Eos.modules.format.UDecimalPad

please re-open if you have an issue..

jcalfee commented 6 years ago

Make sure you don't ignore any promise within your contract block.. Add "return" :

    eos.contract('organiccandy').then((contract) => {
      const args = order.serialize()
      return contract.orderCandy(args, { authorization: 'testuser1234@active' })
    })

The example in the README now uses async so this should be easier to see..