EOSIO / eosjs

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

Error when sending struct as only argument to action #77

Closed nsjames closed 6 years ago

nsjames commented 6 years ago

Version: eosjs ^10.0.0

The following throws the error: TypeError: Cannot read property 'teamid' of undefined Project.teamid projectup.project action.data transaction.actions

// C++
void projectup( Project project ){}

// eosjs
contract.projectup({teamid:'1234'})

The following works

// C++
void projectup( Project project, string nothing ){}

// eosjs
contract.projectup({teamid:'1234'}, '')
jcalfee commented 6 years ago

What does the ABI look like?

nsjames commented 6 years ago
{
      "name": "ClaimReservation",
      "base": "",
      "fields": [{
          "name": "username",
          "type": "string"
        },{
          "name": "sig",
          "type": "signature"
        },{
          "name": "key",
          "type": "id_key"
        }
      ]
    },{
      "name": "claim",
      "base": "",
      "fields": [{
          "name": "claim",
          "type": "ClaimReservation"
        }
      ]
    }

It's not that one specifically but that one does the exact same.

jcalfee commented 6 years ago

I'm wondering if you need something like this:

contract.projectup({Project: {teamid:'1234'}})

If you have the actual ABI that matches projectup that would be helpful.

jcalfee commented 6 years ago

I believe this is accurate.. Please review:

struct Project {
    string              name;
    EOSLIB_SERIALIZE( Project, (name) )
};

class hello : public eosio::contract {
  public:
      using contract::contract;
      void project ( Project project ) {
        print("project called: ", project.name);
      }
};

EOSIO_ABI( hello, (project) )
eos.contract('hello.code').then(hello => {
  const arg = {"project": {"name": "project name"}}
  const auth = {authorization: 'hello.code'}
  return hello.project(arg, auth)
})
# nodeosd --contracts-console
[(hello.code,project)->hello.code]: CONSOLE OUTPUT BEGIN =====================
project called: project name
[(hello.code,project)->hello.code]: CONSOLE OUTPUT END   =====================