I am trying to understand, how the string "100000000.000 SYS" is serialized into struct asset from eosio.token example ( cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS", 0, 0, 0]' -p eosio.token).

Is it built in functionality, or I can define my own custom structure which will be recognized by abi serializer, so I can communicate with my contract like it is done in eosio.token?


You can create your custom struct in code and add EOSIO_SERIALIZE to it. After, you can use it in your contract action parameters like this:

void funcname(const account_name account, st_data_req request);

Then when you push your action, you may use JSON just like in this example:

'["acctname", {"structval1": 12.123123,"structval2": 29.123123}]'

Answering your question with how to serialize it the same way as it's done in "100000000.000 SYS" example you provided - you can write your own string format and parse out struct from it, but I guess that's not what you would want for the first place.


The functionality of the system contracts are built in and can't be changed unless there is consensus amongst the BPs.

However, for your own contract you can create actions and the serializer will figure out what arguments it should take.

For example:

\\\@abi action
void mycontract::test(int x, string y);
EOSIO_ABI( eosio::mycontract, (test) )

or with eosio.cdt as a compiler:

[[eosio::action]] void mycontract::test(int x, string y);
EOSIO_DISPATCH_HELPER( mycontract, (test) )

Can be done with: cleos push action mycontract test '[5,"mystring"]'

or with: cleos push action mycontract test '{"x":"5","y":"mystring"}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.