EOSIO / eosjs

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

Custom contract handling #20

Closed robertkowalski closed 6 years ago

robertkowalski commented 6 years ago

Heya,

I am trying to interact with a custom contract (exchange).

Using the CLI eosc all works well, example message:

eosc push message exchange buy '{"buyer":{ "name": "inita", "number": "1516073924"}, "at_price":"5000000000000000", "expiration":"2018-12-31T23:59:59" , "quantity": "100", "fill_or_kill": "0"}' -S exchange -p inita@active

To me it seems the eosjs APIs are not supporting interactions like this yet - or I am using it wrong.

This code:

  const eos = eos.Localnet({
    keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'
  })

  const options = {
    broadcast: true,
    sign: true,
    scope: [
      "exchange"
    ],
    authorization: [{
      "account": "inita",
      "permission": "active"
    }]
  }

  eos
    .contract('exchange', options)
    .then((exchange) => {
      console.log(exchange)
      console.log("initialised exchange")
    })

Throws with

Error: [
    "Missing uint128 in bid.fields.at_price",
    "Missing uint128 in ask.fields.at_price"
]

It seems to interact with the contract (missing fields), which puzzles me. Any ideas?

When I try to send a message directly without using the contract function, I run into a cache issue:

  const msg = {"buyer":{ "name": "inita", "number": "1516073924"}, "at_price":"5000000000000000", "expiration":"2018-12-31T23:59:59" , "quantity": "100", "fill_or_kill": "0"}

  eos.transaction({
    scope: ['inita', 'initb', 'exchange'],
    messages: [
      {
        code: 'exchange',
        type: 'buy',
        authorization: [{
          account: 'inita',
          permission: 'active'
        }],
        data: msg
      }
    ]
  })

results in:

Error: Abi 'exchange' is not cached, call abiAsync('exchange') message.data transaction.messages

I tested with latest stable and eosjs@prerelease (6.1.1)

jcalfee commented 6 years ago

I need to add the types for encoding numbers larger an 64 bits. I'm thinking they still use the varint encoding but I'm asking about that..

jcalfee commented 6 years ago

eosjs@6.1.2 has been published as the latest release .. Let me know if this fixes everything for you..

robertkowalski commented 6 years ago

thx man!