EOSIO / eosjs

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

TypeError: Unknown struct #113

Closed navcsdev closed 6 years ago

navcsdev commented 6 years ago

When I add one action to eosio.token:

eosio.token.abi

"structs": [
...,{
      "name": "authenticate",
      "base": "",
      "fields": [
        {"name":"from", "type":"account_name"}
      ]
    }
  ],

eosio.token.hpp

...
void authenticate(account_name from);

eosio.token.cpp

...
void token::authenticate(account_name from) {
  require_auth(from);
}

...
EOSIO_ABI( eosio::token, (create)(issue)(transfer)(authenticate) )

When I use eosjs to push account authenticate. I got an error

TypeError: Unknown struct 'authenticate' for contract 'eosio.token', locate this struct or provide serialized action.data action.data = {"from":"eosio.token"} transaction.actions = [{"account":"eosio.token","name":"authenticate","authorization":[{"actor":"eosio.token","permission":"active"}],"data":{"from":"eosio.token"}}]
    at actionDataAppendByteBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs/lib/structs.js:550:17)
    at Object.appendByteBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/fcbuffer/lib/struct.js:108:15)
    at Object.appendByteBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/fcbuffer/lib/types.js:353:16)
    at Object.appendByteBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/fcbuffer/lib/struct.js:110:20)
    at toByteBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/fcbuffer/lib/fcbuffer.js:284:8)
    at Function.toBuffer (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/fcbuffer/lib/fcbuffer.js:271:22)
    at /Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs/lib/write-api.js:616:26
    at /Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs/lib/write-api.js:771:7
    at /Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs-api/lib/exported-helpers.js:69:7
    at /Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs-api/lib/exported-helpers.js:79:7
    at callback (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs-api/lib/process-args.js:70:9)
    at callback (/Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs-api/lib/apigen.js:99:9)
    at /Volumes/DATA/lecle/lite-wallet-eos/node_modules/eosjs-api/lib/apigen.js:126:9
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Thank you !

jcalfee commented 6 years ago

What do you mean "push account authenticate ?

If you already deployed your version of the contract then I see two things to consider:

In the ABI all structs are private until you point to them in the "actions" array (usually at the bottom of the ABI; should be at the top though because that may have prevented confusion here).

Also, make sure your using either eos.transaction with the action "account" pointing your smart contract or you use eos.contract("account", .. Those are the two ways eosjs knows how to query for your ABI file so it knows how to serialize the transaction.

jcalfee commented 6 years ago

Compared to the hello world example, the eosio namespace is on the parent contract not the user's smart contract:

class hello : public eosio::contract {
EOSIO_ABI( hello, (hi) )

reopen if this is still an issue

surabhil commented 6 years ago

I am getting this error too when I try to add actions to the standard eosio.token contract and access using eosjs. Note: it only happens incase of eosio.token.

TypeError: Unknown struct 'approve' for contract 'eosio.token', locate this struct or provide serialized action.data action.data ...
jcalfee commented 6 years ago

@surabhil possibly related: https://github.com/EOSIO/eosjs/issues/271#issuecomment-408606525