EOSIO / eosjs

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

Exception when exec contract action #60

Closed shrimpliu closed 6 years ago

shrimpliu commented 6 years ago

After I deployed the eosio.bios contract, I try to execute setpriv action.

eos.contract('eosio').then(function (contract) {
    contract.setpriv('eosio', 1, { authorization: 'eosio' });
});

Then jump out of the exception:

TypeError: Expecting hex string or buffer in action.data action.data = {"account":"eosio","is_priv":1} transaction.actions = [{"account":"eosio","name":"setpriv","authorization":[{"actor":"eosio","permission":"active"}],"data":{"account":"eosio","is_priv":1}}]
    at actionDataAppendByteBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/eosjs/lib/structs.js:535:17)
    at Object.appendByteBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/fcbuffer/lib/struct.js:108:15)
    at Object.appendByteBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/fcbuffer/lib/types.js:350:16)
    at Object.appendByteBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/fcbuffer/lib/struct.js:110:20)
    at toByteBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/fcbuffer/lib/fcbuffer.js:284:8)
    at Function.toBuffer (/Users/shrimp/work/eos-boot-sim/node_modules/fcbuffer/lib/fcbuffer.js:271:22)
    at /Users/shrimp/work/eos-boot-sim/node_modules/eosjs/lib/write-api.js:611:26
    at /Users/shrimp/work/eos-boot-sim/node_modules/eosjs/lib/write-api.js:766:7
    at /Users/shrimp/work/eos-boot-sim/node_modules/eosjs-api/lib/exported-helpers.js:69:7
    at /Users/shrimp/work/eos-boot-sim/node_modules/eosjs-api/lib/exported-helpers.js:79:7

Error is located here in file eosjs/lib/structs.js:

 var data = typeof object.data === 'string' ? new Buffer(object.data, 'hex') : object.data;
        if (!Buffer.isBuffer(data)) {
          throw new TypeError('Expecting hex string or buffer in action.data');
        }

Do you have any documentation or insight that could help?

rise-worlds commented 6 years ago

yes, plase give examples details of action

jcalfee commented 6 years ago

.. revised comment ..

eosio.system.abi has the transfer function and gets deployed as 'eosio' so you can't use the eosio account for this .. Additionally, eosjs uses a local cache of eosio.system.abi so it will not let you overwrite it. This is why it could not understand your action.data object and it is expecting hex (aka binary) instead.

So, I deployed under an account called eosio.bios ..

eos.contract('eosio.bios', (err, c)=>{console.log(err); eosio_bios=c})
eosio_bios.setpriv('eosio.bios', 1, (err, res) => {console.log(err, res)}) // { authorization: 'eosio.bios' } implied

Then got this error: "eosio.bios does not have permission to call this API"

Using eosjs 8.0.1 ..

So, I'm still investigating the setpriv error..

jcalfee commented 6 years ago

"eosio.bios does not have permission to call this API"

This could be a back-end issue.. Kevin is talking to Anton about this..

jcalfee commented 6 years ago

There are some very brief notes on when and how to load eosio.bios in docker/up.sh .. The EOS team plans to add detailed documentation about this process. Let me know if you have any questions about this, I believe I understand the basics..