Hot answers tagged

15

When declaring a multi_index to use as a table a contract (eg. contracta) you would typically create a struct and typedef similar to this: // @abi table myobjects struct myobject { name sender; // ... other properties here EOSLIB_SERIALIZE(myobject, (sender)(...)) } typedef multi_index<N(myobjects), myobject> myobjects_t; and then create ...


10

So, for this scenario we can create another index that concatenates both indexes and look for it. As an example, let's see a scenario where we can invite accounts to a group and each invitation has an id. // table declaration for invites // @abi table invitation i64 struct invitation { uint64_t id; uint64_t group; account_name user; ...


9

Action names, table names, index names, account names, and everything else you use N(foo), "foo"_n, or eosio::name("foo") for, have these rules. A contract belongs to an account. 12 characters max May contain: a-z, 1-5, or . May not end with . Names are encoded in base-32: . = 0 1-5 = 1 - 5 a-z = 6 - 31 The 5 MSBs of the uint64 contain the first ...


8

After I didn't find any other solution, I ended up with a sequential workaround which will delete all records by time. Disclaimer: Be sure to block all other actions that would rely on the index, because data will invalidate during deletion and new data maybe deleted as well. And you may add some authorization because not everybody should be able to delete ...


7

You can not forbid reading the data from a smart contracts table, because it is exposed by the RPC interface or CLI. What you can do to prevent understanding it by 3rd parties, is encrypt your data like @confused00 said. If you just want to limit access for adding, modyfing or deleting, you can use the scopes of the multi_index and the require_auth method, ...


7

Have a look to available_primary_key in the EOS documentation, multi indexes do support auto increment keys.


7

You have several ways to retrieve data from eos chain as i know. They differs a lot, so you should find a better one for you case. #1. Get from table As you noted there is getTableRows method in eosjs lib, and by default it returns packed response. You can pass option json: true to instruct library to unpack response for you. eos.getTableRows({ code:'...


6

Via the Developers Portal When adding a entry... orders.emplace( payer, [&]( auto& o ) { o.id = 1; o.expiration = 300; o.owner = N(dan); }); The first parameter payer is the account who pays the bill. When modifying an entry... orders.modify( order2, payer, [&]( auto& o ) { o.expiration = 400; }); Payer is the second argument, ...


6

The eosjs library has a format module that will transform account name strings into the appropriate table keys... const Eos = require("eosjs") const BigNumber = require("bignumber.js") const accountName = 'myaccount' const encodedName = new BigNumber(Eos.modules.format.encodeName(accountName, false)) ** Notes: Be sure to pass false to format.encodeName, ...


5

According to the official documentation you can find here: They are multi index tables because they support using multiple indexes on the data, the primary index type must be uint64_t and must be unique, but the other, secondary, indexes can have duplicates. You can have up to 16 additional indexes and the field types can be uint64_t, uint128_t, ...


4

The output was in binary format. If you need the output as json then add "json":true in the data as shown in the command below curl --request POST --url http://bp.cryptolions.io:8888/v1/chain/get_table_rows --data '{"table":"global","scope":"eosio","code":"eosio","limit":10,"json":true}'


4

Just add a created_at field to your table. struct blog { uint64_t id; time created_at; uint64_t primary_key()const { return id; } EOSLIB_SERIALIZE(blog, (id)(created_at)) } typedef multi_index<N(blog), blog> blog_index; blog_index blogs; When creating a record, set created_at to now(). blogs.emplace(_self, [&](auto& x) { ...


3

The scope can be used to narrow down a table list to contain only some fraction of the total entries available. However, you can also have the best of both worlds if you are willing to pay for the RAM involved. Why not create a scope called global, which contains all of the entries from each individual scope, or alternatively contains a list of each scope ...


3

Does anyone have the definition of scope ? To me, it basically looks like a way to compartmentalize data in a contract so that it only accessible within a certain space. In the above example, the data account balance and friends will exist in the contract only for the matching username given. When a different username is given as the scope, a new account ...


3

By using the scope you can have easier fetches. Think of it like the exact index you are searching for without have to use upper/lower bounds. If we take that same logic to a user's info we could do cleos get table contract username account cleos get table contract username balance cleos get table contract username friends instead of cleos get table ...


2

The link below will be really helpful. There are many concepts and relationships between them. https://trybe.one/the-ultimate-end-to-end-eos-dapp-tutorial-part-2/


2

Even if you do not directly support one-to-many, you can set up multiple indexes to: Create a separate player, ticket struct. These become tables. Place a player_id in the ticket and create a secondary index using player_id. You can search for the player's tickets by using both the player_id and the ticket id. The following links can help. https://...


2

I think you can listen to the block with the issue event of eosio.token, only the issue action can update the supply.


2

As per this description i can say that at the time of deployment called A you have not added that table abi that's why you are not able to call getTableRows() but actually the table actions have executed and made entries on table and occupied RAM also.Now, what happens when you redeployed the same contract with same account and made some changes but that RAM ...


2

Yes, you can upload the document on IPFS; and then store the IPFS multihash as a key of your table: Something like this should be useful: // @abi table struct ipfsid { uint64_t key; //the multihash account_name uploader; // the account of the document uploading on ipfs uint64_t primary_key() const { return key; } //multihash is the key };


2

Figured it out, trick was to use a combination of checksum256 and key256. Used the dice contract as an example: struct offer { uint64_t id; account_name owner; asset bet; checksum256 commitment; uint64_t gameid = 0; uint64_t primary_key()const { return id; } uint64_t by_bet()...


2

you can get the ram consume before version 1.2.3 like this: void apply_context::update_db_usage( const account_name& payer, int64_t delta ) { if( delta > 0 ) { if( !(privileged || payer == account_name(receiver)) ) { require_authorization( payer ); } } dlog("the ram used is${delta}",("delta",delta)); trx_context....


2

Meaning of scope You can just make up a scope as you go along. As a general rule there are 3 ways to use the scope: Globally - all table entries are kept in one scope (usually with the name of the contract) cleos get table censuscensus global population Groups - All table entries that are similar in some way share the same scope cleos get table ...


2

If you forgot that, checkout your history setabi action from block explorer, e.g. eosq.app, and you will get the binanry abi. You can either parse the abi binary to readable json, or just construct the setabi transaction and push it to the mainnet, then use command cleos get abi to see your abi.


1

You are not charged for any RPC getter API calls. If you're not forced to sign the transaction, then there's no way to know which account to charge. You're charged if you're changing state or pushing data to the chain.


1

If I understand correctly, and your code is implemented correctly, this can only happen in the case of a fork in the chain. Correctly implemented code would look something like this: auto itr = getTableEntryWithPlayer2EmptyAndStatus1(); eosio::check(itr != mytable.end()); mytable.modify(itr, user, [&](auto & entry){ entry.player2 = user; entry....


1

It took me a while, but I finally solved the issue. Searching on Google for this kind of error, the most interesting source I was able to find was the following: https://github.com/EOSIO/eos/issues/4394. The issue described at the link is not the same as mine, but actually suggested me that there was something wrong when calling an action, from a smart ...


1

Macros should work, but you'd have to edit the eosiocpp script in order to be able to use them when you compile the code. You can't just do eosiocpp -DGEN_TABLE like in normal c++.


1

Updated solution with cleos Just use cleos get code contractaccount -a contract.abi and inspect the abi file. It gives you all structs that define the tables of your contract. Old solution Inspect the history of the account of the contract and find the last deployment of your contract eosio::setabi. Take the binary abi from that action. see for example ...


1

You can use primary key or index to query the data. For the query where, the index provide find and lower_bound and upper_bound method, which returns the iterator, if you have more than one rows, just use code like it below: while(iter != xxx.end()) { iter++; } for lower_bound or upper_bound, or while(iter != xxx.end() && iter->yourdata == ...


Only top voted, non community-wiki answers of a minimum length are eligible