Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
16 votes
Accepted

How to read tables from other smart contracts?

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; ...
Dallas Johnson's user avatar
10 votes
Accepted

How to use two secondary keys as a filter? (WHERE f1 AND f2)

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 ...
Leo Ribeiro's user avatar
  • 3,023
9 votes
Accepted

What are naming rules for actions, tables and contracts?

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 ...
Todd Fleming's user avatar
  • 2,005
8 votes
Accepted

Reading table rows with EOSJS

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 ...
user1114775's user avatar
8 votes
Accepted

Delete all multi_index records without iterator?

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, ...
tmm's user avatar
  • 2,114
8 votes
Accepted

scope in the get table command

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 ...
Phillip Hamnett - EOS42's user avatar
7 votes
Accepted

Can we add the permission to access the table?

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 ...
tmm's user avatar
  • 2,114
7 votes

HOWTO: auto increment primary key?

Have a look to available_primary_key in the EOS documentation, multi indexes do support auto increment keys.
Jolo's user avatar
  • 71
6 votes
Accepted

Get table rows HTTP API in JSON

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/...
Gopalakrishnan Nadar's user avatar
6 votes
Accepted

EOSjs getTableRows lower and upper bound on account name

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 ...
Tyler J Kuhn's user avatar
6 votes
Accepted

How do you define who pays and who stores on your Smart Contract tables?

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 ...
John Williamson's user avatar
5 votes
Accepted

Is it possible to use a type other than uint64_t for a table primary key?

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 ...
damianodamiano's user avatar
4 votes

Is it possible to get the creation timestamp of a record of a Smart Contract Table?

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 ...
Angelo Laub's user avatar
3 votes
Accepted

Trying to pass a sha256 hash to my contract and store it

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 ...
James Hollister's user avatar
3 votes

When to use or not use the Contract Scope?

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 ...
Phillip Hamnett - EOS42's user avatar
3 votes

When to use or not use the Contract Scope?

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 ...
Magic Man Xpress's user avatar
3 votes

When to use or not use the Contract Scope?

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 ...
nsjames's user avatar
  • 453
2 votes

One-to-many relationship in Multi Index Tables

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/
smarteasy's user avatar
  • 1,015
2 votes

One-to-many relationship in Multi Index Tables

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 ...
smarteasy's user avatar
  • 1,015
2 votes
Accepted

How to retrieve historical EOS supply?

I think you can listen to the block with the issue event of eosio.token, only the issue action can update the supply.
Jimmy Guo's user avatar
  • 1,066
2 votes
Accepted

Assertion failure after updating a smart contract with tables

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/...
Riccardo Persiani's user avatar
2 votes
Accepted

Same name table of different contracts got merged

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 ...
Mr.Y's user avatar
  • 957
2 votes

Can we store documents in a table.If yes, Is this a right approach?

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 ...
Riccardo Persiani's user avatar
2 votes

How can I know if I pay ram for a row in a table?

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 || ...
fen chen's user avatar
  • 163
2 votes
Accepted

How to properly use cleos get table with --key-type sha256 / secondary index (failing on 1.4.2)

@gustavomick , I think the issue is with the way you pack key256 in checksum256_to_sha256 I tested your code with static key256 checksum256_to_sha256(const checksum256 &hash) { const uint128_t ...
Vladimir Venediktov's user avatar
2 votes

Smart contract - find on two columns

Depending on other logic implemented in the contract I'd personally choose this implementation: struct [[ eosio::table, eosio::contract("whisper") ]] posts { uint64_t key; //Primary key (ID) ...
cmadh's user avatar
  • 1,929
2 votes
Accepted

why i get "uniqueness constraint was violated" on error on empty table?

You need to delete all instances of the old database structure before you can mutate it, I believe an instance still exists in the ether despite it not showing up anymore. If you're just on a local ...
John Williamson's user avatar
2 votes

Get Table Rows with Pagination

This has its limitations but if you are fetching a table by the primary key which is an incremented integer value, you could use a combination of lower_bound, upper_bound, and limit and do something ...
mayur relekar's user avatar
2 votes

How to delete record on EOS if I forget table structure

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 ...
Jimmy Guo's user avatar
  • 1,066
2 votes
Accepted

cleos data getting inserted and deleted but table shows empty record

You set get_first_receiver() as the scope of member_index. If this action is not sent by other contract, first_receiver will be the account where the contract is deployed. [[eosio::action]] void ...
conr2d's user avatar
  • 2,320

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