EOSIO / eosjs

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

Irrelevant authorities error? #2

Closed liamcurry closed 6 years ago

liamcurry commented 6 years ago

I've deployed the tic tac toe example and am now trying to create a new game with eosjs, but I'm getting errors about irrelevant authorities?

Here's the code I'm trying to run:

eos.contract('tictactoe').then(c => c.create({ host: 'inita', challenger: 'initb' }))

But when I run that I get these errors:

screenshot

Here's the payload for that push_transaction request:

{
    "ref_block_num":8158,
    "ref_block_prefix":1085591932,
    "expiration":"2017-11-23T08:13:11",
    "scope":[
        "inita",
        "initb"
    ],
    "read_scope":[

    ],
    "messages":[
        {
            "code":"tictactoe",
            "type":"create",
            "authorization":[
                {
                    "account":"initb",
                    "permission":"active"
                }
            ],
            "data":{
                "challenger":"initb",
                "host":"inita"
            }
        }
    ],
    "signatures":[
        "1f5d41e3077f3d71b0155203a62d4ab86317cd8bbedb48f37b12471e0da0bdb1111852576e65fa9ffbaf860969f363b280b9971ce5c7012e84edcc002e2de33cf9"
    ]
}

I also tried creating the transaction manually like this:

eos.transaction({
  scope: ['inita', 'initb'],
  messages: [
    {
      code: 'tictactoe',
      type: 'create',
      authorization: [],
      data: {
        host: 'inita', challenger: 'initb'
      }
    }
  ]
})

But then I get different errors about missing required keys:

screenshot

Any idea what's causing this? Am I doing something wrong? Thanks.

liamcurry commented 6 years ago

Here's the tic-tac-toe.wast file: https://gist.github.com/liamcurry/8c107e14fe05a5a2fa9befee2f72a976

liamcurry commented 6 years ago

Okay I think I've partially figured out the issue. I have the contract account named tictactoe, but there's a check in the contract for code tic.tac.toe here: https://github.com/EOSIO/eos/blob/master/contracts/tic_tac_toe/tic_tac_toe.cpp#L195

I changed that to be tictactoe and now I can create games with eosc and with eos.transaction like this:

eos.transaction({
  scope: ['inita', 'initb'],
  messages: [
    {
      code: 'tictactoe',
      type: 'create',
      authorization: [{ account: 'inita', permission: 'active' }],
      data: {
        host: 'inita', challenger: 'initb'
      }
    }
  ]
})

However I'm still getting errors when I try this code:

eos.contract('tictactoe').then(c => c.create({ host: 'inita', challenger: 'initb' }))

screenshot

jcalfee commented 6 years ago

eosjs could not figure out the correct authorization in this case.. As a work-around, try supplying your own "authorization" as an option (last parameter) to c.create({}, options)

https://github.com/EOSIO/eosjs#options

jcalfee commented 6 years ago

Related: https://github.com/EOSIO/eos/issues/401

jcalfee commented 6 years ago

This works:

    const game = await eos.contract('tic.tac.toe')
    await game.create(
      {challenger: 'inita', host: 'initb'},
      {
        scope: ['inita', 'initb'],
        authorization: ['initb@active']
      }
    )
davidfrothin commented 6 years ago

const game = await eos.contract('tic.tac.toe') SyntaxError: await is only valid in async function

eos.contract('tic.tac.toe').then((contract) = { contract.create( {challenger: 'inita', host: 'initb'}, { scope: ['inita', 'initb'], authorization: ['initb@active'] }) })