Questions tagged [smart-contract]

Anything related to decentralized application (dApp) development, concepts, and possibilities with smart contracts, or technical questions for the development of smart contracts.

Filter by
Sorted by
Tagged with
28 votes
3 answers
576 views

Is there a standard for naming and formatting that EOS projects should follow / EOS C++ coding style?

Coming from other C++ projects like Unreal Engine I was surprised to see coding standards in the EOS codebase is all lowercase, not only for variables but even for class names. Is there any resource ...
Soleone's user avatar
  • 674
16 votes
2 answers
3k views

How to read tables from other smart contracts?

I tried to look for inside the EOS repository and contracts examples but I could not find anything like this. I want to know how can I read another contract table. So, as an example: my contract ...
Leo Ribeiro's user avatar
  • 3,023
12 votes
1 answer
2k views

What is the purpose of `require_recipient`?

I saw the description of the function require_recipient and it says: Add the specified account to set of accounts to be notified I would like to understand what's the purpose of receive this ...
Leo Ribeiro's user avatar
  • 3,023
11 votes
1 answer
970 views

What are naming rules for actions, tables and contracts?

Since strings internally are converted to uint64 for space efficiency on the eos.io blockchain what are the restrictions that need to be followed for: actions tables index identifiers (within ...
Dallas Johnson's user avatar
11 votes
2 answers
604 views

How to airdrop a new token to EOS holders?

If I'm developing a project on EOS that will require a new custom token I might want to do an airdrop of that token to existing EOS holders. Are there best practices on how to go about that? Roughly ...
Soleone's user avatar
  • 674
10 votes
3 answers
2k views

How to do an inline transfer of a token?

When I perform a token transfer from the cleos command line, it works with no problems: $ cleos push action eosio.token transfer '["rider2","vehicle1","1000.0000 TOK","initial"]' -p rider2 executed ...
Max's user avatar
  • 411
10 votes
1 answer
627 views

Compile Rust to WebAssembly for EOS Smart Contract?

So I'm familiar with the fact that the supported language for EOS smart contracts is C++. However, the EOS docs mention that even the C++ needs to compile down to WebAssembly. So my question is, ...
semore_1267's user avatar
9 votes
2 answers
2k views

How to validate if an Account exists?

I know that we have require_auth to check for permission, but I'm looking for something like is_valid_account to check if the account exists and is active in the chain. Do we have anything like that?...
Leo Ribeiro's user avatar
  • 3,023
9 votes
1 answer
639 views

Removing contract to release RAM - the smallest contract possible

Check our github https://github.com/irespo/irespo/tree/master/irespo/iresporemove I did a sample contract with one empty action, but it is still 30 KB. I tried a contract without action, but did not ...
Filip Niziol's user avatar
9 votes
2 answers
634 views

Which version of C++ can I use in smart contracts?

Which version of C++ can I use to implement smart contracts? For example: C++11, C++14 or C++17? Do we have any constant or doc where it is defined? Also, in my understanding the code is sandboxed, ...
Danail's user avatar
  • 536
9 votes
1 answer
2k views

How to clear all of the data in my contract table? [duplicate]

I know I can user erase to clear the table, but this method only clear one data at a time and must write a action to do that. Is there any easy way to do that?
yang24201's user avatar
  • 393
9 votes
2 answers
1k views

Is there a function to return the size of a multi_index table?

Is there a function to return the size of a multi_index table? If not is there a better way then looping through them? uint64_t count; for (auto itr = table.begin(); itr != table.end(); ++itr) { ...
Magic Man Xpress's user avatar
9 votes
2 answers
932 views

Is there any method to remove a useless contract from the blockchain just like "selfdestruct" in ETH?

As I know, in ETH, when a contract would be useless, it could be destroyed by using the "selfdestruct" action. So, is there any same method to remove a useless contract from the eos blockchain?
Harry Ma's user avatar
  • 555
9 votes
1 answer
115 views

Issue a transaction on a foreign blockchain

What is the correct way to send a transaction to the bitcoin blockchain from an EOS smart contract. Can anyone provide a code example ?
Evandro Lorenzoni's user avatar
8 votes
2 answers
1k views

How to convert public key string to char[34] inside contract?

I need a way to convert a public key string (e.g. "EOS8KgkQikWK84J2jJ1Nvd3ttfJNRicYZsdbunbe9biR99dHGb24a") into a struct public_key { char[34]; } inside of a contract. The char[34] seems to be ...
Angelo Laub's user avatar
8 votes
1 answer
920 views

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

In the contract multi index tables we can filter by the primary key or we can just create an indexed_by as an additional index. Then we have basically two options: filter by the primary key or ...
Leo Ribeiro's user avatar
  • 3,023
8 votes
1 answer
2k views

What does require_auth (_self) do in EOS?

I have seen in numerous places that the following is coded - require_auth (_self); Aside from the intuitive meaning that it requires a user to be authorised, what exactly does it do and how?
Trevor Oakley's user avatar
8 votes
2 answers
477 views

Best practice to handle table migrations?

What is the best practice for migrating table when a member of a struct is added? For some structs, I have had no problems adding members, but for others I have. I get this error message: $cleos get ...
Max's user avatar
  • 411
8 votes
2 answers
823 views

Encrypting with a public key

I have user specific data in a table on my smart contract that I don't want others to see. Can I encrypt that data with a public key of the user? If possible then how to encrypt that data with the ...
kstnew's user avatar
  • 103
8 votes
1 answer
463 views

How to add a unit test for a new contract [duplicate]

I am currently on eosio v1.1 but will be upgrading to v1.2 shortly. I am trying to create a new unit test for my contract. The existing unittest work when I run the following: cd eos/build/unittest ...
Magic Man Xpress's user avatar
8 votes
0 answers
110 views

How do you properly change/add to the struct that is stored in a table as part of a contract upgrade? [duplicate]

Does this even work? Seems like I've broken my tables doing this but I have changed my contract pretty significantly. I'd imagine that someone may want to add a new "column" (member) to their "...
Jesse's user avatar
  • 81
7 votes
1 answer
2k views

How to convert an account_name to a string?

I need to be able to convert a name/account_name to a string for some processing in my smart contract. I have found and used the string_to_name function for converting in the other direction, but ...
John Haager's user avatar
  • 1,844
7 votes
2 answers
417 views

Is there a flaw in deciding who can pay for RAM?

Lets say I interact with an action from a smart contract, if I'm not careful and didn't read or couldn't understand the source code for the smart contract, is it not possible that the contract could ...
Phillip Hamnett - EOS42's user avatar
7 votes
1 answer
689 views

How to debug eosio::on_notify("eosio.token::transfer") actions?

I'm working on a contract that will run an action when receiving tokens. The following code does not run when the account receives EOS or JUNGLE tokens on the Jungle Testnet. #include "./test.hpp" .....
marijn's user avatar
  • 71
7 votes
3 answers
1k views

Why the first time I execute an action I get "Error 3080006: transaction took too long"?

WHAT I WANT Call an action and see it succeed at the first execution. WHAT IS NOT WORKING The function, which I am executing, the first time fails with error: Error 3080006: Transaction took too long ...
Riccardo Persiani's user avatar
7 votes
1 answer
577 views

Can we add the permission to access the table?

I know how to declare ,initialize and get,set values in a table .My question is Can we add permission to access the table to a particular user inside our smart contract ?
Nirdesh Kumar Choudhary's user avatar
7 votes
2 answers
2k views

How to uninstall a deployed contract?

I bought some RAM for my contract. Now I want to uninstall my contract,and unstake the RAM. what should I do ? Can the RAM be unstaked?
mooninwater's user avatar
7 votes
2 answers
404 views

What libraries are supported by contracts?

What libraries can be used when writing a contract in C++? What are the limitations? If I have a library I normally use and like, how do I compile it for use by contracts?
expaand's user avatar
  • 654
7 votes
1 answer
462 views

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

Sometimes I find myself lost deciding how I will store data for my application. I have a dilemma about: Decentralization vs Accessibility for everybody? Looking to this table, which manage DAOs: // ...
Leo Ribeiro's user avatar
  • 3,023
7 votes
2 answers
1k views

What's the difference between `asset` and `extended_asset`?

tl;dr: I just wanted to reuse a "token currency type" with symbol and precisions validations out-of-the-box. If I’m implementing “token” currency in my contracts, which one should I use? I’m just ...
Leo Ribeiro's user avatar
  • 3,023
7 votes
1 answer
837 views

How can a action be scheduled to execute at specific timestamp or block?

Is it possible to schedule an action defined within a contract to be automatically executed at a specific timestamp or block? I know it's possible to get a timestamp inside of a contract but, I'm ...
Joshua Shope's user avatar
7 votes
1 answer
368 views

Developing Smart Contracts with Docker

If I have the eos chain running in a Docker container, how can I interact with it from my local file system? I would love to be able to create my contracts, compile them, and deploy to my docker ...
cipherz's user avatar
  • 201
7 votes
1 answer
432 views

Unit testing custom contracts [duplicate]

What is the best way to write contracts in a TDD style? The eos source repo has unit tests which seem to be focused around testing the platform but my question is focused at the next level up (based ...
Dallas Johnson's user avatar
7 votes
1 answer
140 views

Using "native" wat/wasm function in smart-contract

I have to do some heavy computation in my smart-contract, like say a+b. Fortunately, I have written some very efficient implementation in "native" (web)assembly, like: File add.wast: (module (func ...
Codringher's user avatar
6 votes
2 answers
2k views

How to use checksum256 secondary index to get table rows

Does anyone know the correct way to get table rows using checksum256 (fixed_bytes<32>) secondary index through the get_table_rows RPC API? I found a way using key256, but key256 is deprecated ...
m0t0k1ch1's user avatar
6 votes
3 answers
1k views

When to use or not use the Contract Scope?

Analyzing the eosio.token contract we see that the token stats is stored under the SYM scope. So if I want to read a token stat, like supply, I need to execute: cleos get table eosio.token EOS stats ...
Leo Ribeiro's user avatar
  • 3,023
6 votes
2 answers
328 views

How is the total available capacity (ram/cpu/bandwidth) communicated among block producers

The token model section of the eos.io white paper states: Block producers publish their available capacity for bandwidth, computation, and state. This is a bit vague and I am trying to answer a ...
Vlad's user avatar
  • 885
6 votes
3 answers
2k views

How to convert asset to string in a contract?

How to convert asset to string in a contract? asset my_asset = asset(10000, S(4, EOS)); string my_asset_string = ??? //How to convert my_asset to a string "1.0000 EOS"?
mochunhei's user avatar
  • 277
6 votes
1 answer
1k views

How I can typecast the "0.0001 EOS" into eosio::asset

I declared a variable value = "0.0001 EOS"; , inside my action I want to transfer those asset to a account .I am having difficulty to typacasting this string into the eosio::asset value . my code goes ...
Nirdesh Kumar Choudhary's user avatar
6 votes
3 answers
1k views

Is there event emitting function in smart contract?

I am porting Ethereum smart contract in Solidity to EOS platform, but I meet a problem: how to send some events to Dapp so as to update the UI? Now I have to poll the table the smart contract saved ...
ofo's user avatar
  • 320
6 votes
1 answer
1k views

How to get my contract balance in my smart contract? [duplicate]

I have copy the account struct from the smart contract eosio.token into my own contract and typedef multi_index like this: //@abi table accounts i64 struct account { asset balance; uint64_t ...
yang24201's user avatar
  • 393
6 votes
1 answer
51 views

Make Ledger Reflect All RAM Changes

If we want those witnessing the chain to know about our apps state without any knowledge of our service layer, what might be the best approach? Since the ledger only records the data given to it in an ...
cSun's user avatar
  • 61
6 votes
2 answers
598 views

How can I develop a simple Escrow contract?

I'd like to develop a simple Escrow smart contract. It will designate 3 parties, the buyer, seller and arbiter. A simple use case would be... The buyer doesn't trust that the seller will send an ...
John Williamson's user avatar
6 votes
1 answer
151 views

How to add third part libraries when developing smart contracts in EOS?

For example, if I want to add a random digital generator library, what can I do? I want to add all the source files into my contract directory?
yang24201's user avatar
  • 393
6 votes
1 answer
81 views

How does eosio support complex structure as the input of a contract's method?

AFAIK, the data type in Wasm only supports i32,i64,f32,f64, but when we use eosio contract, we can pass a string as a parameter. Anyone can tell me how eosio does that?
Stephen D's user avatar
6 votes
3 answers
319 views

Is it possible to see a smart contract code hash from within a smart contract?

I would like to check the code hash of an account from within my smart contract. Is this possible?
Phillip Hamnett - EOS42's user avatar
5 votes
1 answer
595 views

How to calculate the RAM size of a contract in EOSIO and then i can know how much EOS i need to pay for every contract

How can I calculate the RAM size of a contract in EOSIO? I mean, is there any tool from EOSIO? Could this tool help me to know how much EOS I need to prepare for every contract.
Harry Ma's user avatar
  • 555
5 votes
2 answers
2k views

How to get current time in different versions of EOSIO

Depending on which version of EOSIO you use, there are different options available for finding the current time. What are they?
Phillip Hamnett - EOS42's user avatar
5 votes
2 answers
2k views

Clearing RAM tables of eosio.token contract

What I am trying to do is clear the RAM table completely. This question is not a duplicate since it is asking for a full and a working solution. The contract that I was executing filling the RAM ...
Damir Olejar's user avatar
5 votes
1 answer
3k views

How to do an action in a contract to transfer tokens to other user accounts without adding permission in dawn4.0? [closed]

How to do an action in a contract to transfer tokens to other user accounts without adding permission? Actually, in dawn3.0 i can use the function like this below, but in dawn 4.0 it doesn't work ...
Harry Ma's user avatar
  • 555

1
2 3 4 5
13