Hot answers tagged

11 votes

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

eosiocpp currently compiles contracts using c++14. cib compiles contracts using the c++17 language, but c++14 library. sandboxing: contracts are compiled to WASM. Normal OS functions (filesystem, ...
user avatar
  • 1,985
6 votes

Which IDE can I use for EOS C++ source code?

Today I'm using Visual Code (which works in Linux, because I'm on OSX) but I think the easiest one to setup with a nice intellisense (autocomplete), debug and tests is CLion from Jetbrains. In this ...
user avatar
  • 3,023
4 votes
Accepted

eosio.cdt 1.3.2 indexed_by error: non-type template argument is not a constant expression

Figured it out. In case anyone else has this issue. Looks like the index name can't have an underscore in it. Changed to: typedef multi_index<"settings"_n, setting, indexed_by<"...
user avatar
3 votes

How to convert asset to string in a contract?

Actually asset is a struct variable like this: struct asset { /** * The amount of the asset * * @brief The amount of the asset */ int64_t amount; ...
user avatar
  • 163
3 votes

Building smart contract error: redefinition of 'time' as different kind of symbol typedef uint32_t time;

The problem is that the code you have written is somehow accessing both the standard C++ definition of time (from /usr/include/time.h) and also the EOS.IO definition of time (from ../eosiolib/types.h)....
user avatar
3 votes

What libraries are supported by contracts?

The code for Boost is in https://github.com/EOSIO/eosio.cdt/tree/master/libraries/boost The main EOS library is eosiolib, and it uses Boost in action.hpp, dispatcher, datastream, etc.
user avatar
  • 131
3 votes

What libraries are supported by contracts?

Contracts are in WASM which is a compiled binary language. The only currently tested and validated language for EOS smart contract development is C++, but in theory any language that compiles down to ...
user avatar
  • 141
3 votes

Is it possible to set up a smart contract with multiple .cpp and .hpp files?

It is possible: Set up a new smart contract environment using eosio-init: eosio-init -project=mycontract -path=. Create all of your .cpp and .hpp files as appropriate In the ./src folder, edit the ...
user avatar
3 votes
Accepted

how to find greatest common divisor inside smart contract?

You should have #include <numeric> to use std::gcd in your code.
user avatar
  • 2,270
2 votes
Accepted

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

Updated answer: Currently EOS smart contracts are written in C++17. For more details see the official SDK, CDT (Contract Development Toolkit) which is based on clang 7.
user avatar
2 votes

Is it possible to compile a smart contract using g++ or clang?

With eosio.cdt, it is now possible to compile object code which can then be tested using unit tests. Check out https://eosio.github.io/eosio.cdt/1.5.0/guides/native-tester.html for a detailed guide. ...
user avatar
2 votes
Accepted

What's the difference between "time" and "time_point_sec"?

time is just a typedef for uint32_t, so it has no time-related functionality or restrictions¹ as long as you don't try to represent milliseconds (which you will need if you try to represent block time,...
user avatar
  • 5,524
2 votes

How to convert asset to string in a contract?

You cannot use functions from ./libraries/chain/asset.cpp directly in your contract. The only available part of EOS API you can use in contacts is located in ./contracts/eosiolib/ folder. There are ...
user avatar
  • 63
2 votes
Accepted

Do all Smart Contracts use the eosio namespace?

eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive ...
user avatar
  • 5,524
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/...
user avatar
2 votes

How to parse iso8601 to eos time format?

This example does not work: void show(const std::string& time_str) { const time_point& current_time = time_point::from_iso_string(time_str); print(current_time.elapsed._count); } ...
user avatar
2 votes

Transfer EOS tokens inside a smart contract from an account to another

First of all you need to provide the permission of eosio.code. After that you can use the transfer action of eosio.token contract. before assigning tokens see if both .abi and .wast file are there, ...
user avatar
2 votes

Transfer EOS tokens inside a smart contract from an account to another

Use the following code in your smart contract to initiate a transfer of EOS tokens. asset quantity = asset( 10000, symbol_type(S(4, EOS)) ); // equals to 1 EOS action( permission_level{ _self, N(...
user avatar
2 votes

Setting up C++ developing environment

Setting up a development environment is simple, just follow the first page of the wiki, here: https://github.com/EOSIO/eos/wiki/Local-Environment
user avatar
  • 1,686
2 votes
Accepted

How to solve fatal error: 'eosiolib/types.hpp' file not found #include <eosiolib/types.hpp>?

With eosiocpp everything works fine because types.hpp is defined in the directory ...\eos\contracts\eosiolib. In eosio.cdt in ...\eosio.cdt\libraries\eosiolib there is only types.h and not types.hpp ...
user avatar
2 votes

Trouble using EOSIO built in crypto library (can't resolve headers)

The correct library is now #include <eosio/crypto.hpp>
user avatar
2 votes

Type mismatch error when creating iterator

I identified the problem - later in the function I'm trying to create a new extended asset by adding two extended assets together, and they don't have the same extended symbol. I'm really not sure ...
user avatar
1 vote

How to handle exceptions in the smart contract?

There is no exception handling in web assembly, therefore you can't implement it in the C++ code either. Update: Deferred transactions are deprecated in EOSIO, so I do not recommend using them. The ...
user avatar
1 vote
Accepted

Why smart contract function fails with "Error 3090004: Missing required authority"?

The issue was inside an emplace(). Basically, I was not setting the payer. After, hard coding the payer as N(mycontract), I don't get the error anymore and the functions work correctly.
user avatar
1 vote
Accepted

Whats the use of EOSLIB_SERIALIZE?

EOSLIB_SERIAlIZE is a DataStream Seralizater , if you want to deep dive into what it does you should go to contracts/eosiolib/serialize.hpp in your EOS directory. It basically gives the struct extra ...
user avatar
1 vote

How do I use C++11 on Mac?

To use this syntax, you need to be compiling with the latest version of eosio.cdt. When you build and compile eosio.cdt, it will install the appropriate clang compiler for you, and eosio-cpp will be ...
user avatar
1 vote

Time dependent EOS unit test

You can use timestamp to have this functionality. You can use now() this function will return you current timestamp(in seconds),you can set your own timestamp with help of this function Let say for ...
user avatar
  • 957
1 vote
Accepted

How to use std::tuple with eosiocpp?

Multiple inheritance not supported for this particular case means that you can only have a tuple of single type. typedef std::tuple<double> location_t; According to this answer one is not able ...
user avatar
1 vote

Convert string to float or double

I hope this can help double stringtodouble(string str) { double dTmp = 0.0; int iLen = str.length(); int iPos = str.find("."); string strIntege = str.substr(0,iPos); string strDecimal = str....
user avatar
1 vote

Convert string to float or double

I recently had this problem. I discovered that atoi() actually works (nothing else did). so I wrote it like this: float token::stof(std::string s, float def) { if (s == "") return def; ...
user avatar
  • 495

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