Questions tagged [c++]
All questions related to the use of C++ within the EOSIO framework
62
questions
9
votes
2
answers
640
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, ...
7
votes
2
answers
410
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?
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"?
3
votes
3
answers
1k
views
Which IDE can I use for EOS C++ source code?
What I need is an IDE as advanced as Eclipse, that would tell me if certain imports are missing, variables not declared, compile errors, and so on... I am using Linux so Visual Studio won't work for ...
3
votes
1
answer
191
views
eosio.cdt 1.3.2 indexed_by error: non-type template argument is not a constant expression
I'm trying to shift my contract and build it with the latest CDT, v1.3.2.
The transition docs say to use the new ""_n name constructor but it doesn't appear to be working.
I have:
typedef ...
3
votes
2
answers
666
views
Building smart contract error: redefinition of 'time' as different kind of symbol typedef uint32_t time;
I am pretty desperate at this point to search for hints on this issue, though I am pretty sure it's because I'm new to C++ include system.
I am getting an error while trying to run a wasm executable ...
3
votes
2
answers
291
views
How to handle exceptions in the smart contract?
Let's say I need to send some EOS to 2 different addresses from within a smart contract!
Now, let's suppose that one of those addresses is actually a smart contract and can reject the transfer! In ...
3
votes
2
answers
167
views
Do all Smart Contracts use the eosio namespace?
I'm new to creating Smart Contracts on EOS and I've followed a few tutorials (for example the official Hello World guide).
Would someone be able explain why all of the examples seem to use the ...
3
votes
1
answer
2k
views
What's the difference between "time" and "time_point_sec"?
Seems that they are both datatype for storing number of seconds that have elapsed since 1970.
So what's the difference between them, when should I use which?
Edit:
An example of the "time" datatype I'...
3
votes
1
answer
494
views
Why smart contract function fails with "Error 3090004: Missing required authority"?
WHAT I WANT
From the contract mycontract I want to call a function function1.
The function function1 calls another function of mycontract called function2. The function function2 calls an action of ...
3
votes
1
answer
605
views
Whats the use of EOSLIB_SERIALIZE?
I understand that it is used for serialization and deserialization of a struct but why does anybody want to serialize/deserialize the struct? What's the use case?
3
votes
1
answer
305
views
How can I call third party APIs from inside a smart contract at a set time or interval?
In a scenario where a smart contract needs to check against a third party service (Let's say an API with weather information from a trusted source like Weather.com) and make a decision on moving ...
2
votes
1
answer
58
views
how to find greatest common divisor inside smart contract?
I need the greatest common divisor between two numbers in the smart contract. I tried:
int gcd = __gcd(num1, num2);
num1 and num2 are two numbers. When the smart contract is compiled, its generating ...
2
votes
2
answers
841
views
How to solve fatal error: 'eosiolib/types.hpp' file not found #include <eosiolib/types.hpp>?
After installing eosio.cdt 1.4.1, I am receiving this error from the compilation of my code where is included the header file eosiolib/types.hpp:
fatal error: 'eosiolib/types.hpp' file not found
#...
2
votes
1
answer
107
views
Can I make a http request from smart contract code?
I know that eosio has http plugins, which is why I'm thinking that maybe a http library is embedded to the eosio.hpp and that I can use it internally to send http requests. Is this possible?
My goal ...
2
votes
1
answer
483
views
Using transfer to send tokens within a smart contract results in "unable to find key"
This is my example code deployed on myaccount
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/currency.hpp>
using namespace eosio;
class ...
2
votes
1
answer
313
views
Runtime Error Processing WASM in ``` std::stof```?
[[eosio::action]]
void hi(){
string strNum;
strNum.push_back('3');
float currNum = std::stof(strNum);//
print("currNum=",currNum);
}
...
2
votes
3
answers
306
views
Can I use uint256_t in EOS smart contracts?
I want to use uint256_t in my EOS smart contract but I am getting following error
unknown type name 'uint256_t'; did you mean 'uint16_t'?
I thought EOS supports uint256_t as I read it in some EOS ...
2
votes
2
answers
134
views
How to use std::tuple with eosiocpp?
I am trying to use typedef std::tuple<double, double> location_t; to create a simple tuple with latitude and longitude, but eosiocpp gives me
2018-09-02T12:54:47.310 thread-0 main.cpp:105 ...
2
votes
0
answers
241
views
What are the main differences betwen EOSIO multi_index and Boost multi_index?
Inspired by this comment, I was wondering what are the main differences between eosio::multi_index and boost:multi_index and why do they exist?
The documentation notes that there are important ...
1
vote
1
answer
133
views
Is it possible to set up a smart contract with multiple .cpp and .hpp files?
If we want to make our smart contract code modular, and keep each class, contract, and table in its own file, is it possible to do this, and if so, how?
1
vote
1
answer
61
views
Type mismatch error when creating iterator
I'm getting a type mismatch error when I try to execute an action. Here is the line that's causing problems:
auto iterator = table.require_find(primary_key, ("Could not find entry " + std::to_string(...
1
vote
2
answers
73
views
Contract won't keep index count inside index table
Attempting to keep track of an index for future use as an index in another container.
uint64_t namehash = ::eosio::string_to_uint64_t(my_name.c_str());
auto name_iter = ...
1
vote
1
answer
877
views
Assertion failure after updating a smart contract with tables
Before the update
Before the update of the code of my c++ smart contract, this uses to work absolutely fine. Data storing on the table and actions execution were done successfully.
After the update
...
1
vote
1
answer
162
views
How to parse iso8601 to eos time format?
How does one parse an iso8601 string to eos time_point format?
1
vote
1
answer
230
views
Is it possible to compile a smart contract using g++ or clang?
I want to write and execute some unit tests on a smart contract outside of nodeos, but to do that I need to be able to compile the code the normal C++ way, using g++ or clang, so that I get object or ...
1
vote
1
answer
74
views
What is the way to create a map from 256 bit integers to values?
What is the way to create a map from 256 bit integers to values?
Is it std::map<>? or will std::map<> become slow as the data grows? If it is slow, what is faster?
1
vote
1
answer
89
views
Defining symbols for a contract at compile time - how?
supposing I have a contract declaration in file t.cpp as follows:
class [[eosio::contract("__CONTRACT__")]] token : public contract {
I would expect to be able to compile it like this:
$ eosio-cpp -...
1
vote
1
answer
239
views
How can i solve the error: iostreams currently clash with eosio::datastream?
I am trying to compile some code which compiled successfully with the old compiler eosiocpp, but with the new eosio-cpp gives me: eosio.cdt/1.4.0/bin/../include/libcxx/iostream:13:2: error: "iostreams ...
1
vote
2
answers
249
views
Error 3015004 when creating tokens in tutorial
Caseys-MBP:eosio.token casey$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active
Error 3015004: The type defined in the ABI is invalid
Error Details:
...
1
vote
1
answer
83
views
How do I use C++11 on Mac?
I tried the hello world sample contract, and when it came time to compile, I got this error:
hello.cpp:10:10: error: expected ']'
[[eosio:action]]
^
...
1
vote
1
answer
135
views
Time dependent EOS unit test
My contract has time dependent actions, which I want to test.
How can I mock the clock in the smart contract such that I can set it to any time I want?
An example of one action that is time ...
1
vote
1
answer
117
views
How to retrieve data from multi index table? i a=have stored data dynamically using emplace method now how to get it back as a Record?
I have used this code to store the data(name and marks) in the table, now i want to retrieve that data in the form of record. how can i get that?
void addmarks(account_name examiner, account_name ...
1
vote
1
answer
205
views
Error 30700002: Smart contract's apply function not exported; non-existent; or wrong type
I have written a smart contract and I want to start testing it, it contains an apply function, which currently checks for a transfer, and then calls the appropriate function:
void mycontract::apply(...
1
vote
1
answer
151
views
How to get current RAM price inside a contract in C++?
How can I programatically get the current(last) RAM price inside an EOS smart contract in C++?
I need to handle the data inside the smart contract for an experiment.
1
vote
0
answers
34
views
Build existing autoconf C project to include in smart contract
I'd like to include GNU's GMP library in my smart contract project.
It's an autotools/autoconf project, how can I compile it as a standalone webassembly library and then include it in my smart ...
1
vote
1
answer
49
views
Profiling EOS.IO smart contract code
What's the best way for profiling the code of an EOS.IO smart contract?
I'd like to know what percentage of the CPU time is spent on executing each function\line (including multi index table function ...
1
vote
1
answer
78
views
RPC Wallet integration API throwing an error
I am new with blockchain services. I have created wallet using command line.
curl -X POST http://127.0.0.1:8888/v1/wallet/create -d '"WalletTest"
It's created successfully.
But, I'm trying to ...
1
vote
1
answer
454
views
Transfer tokens inside a smart contract from an account to another account
I need to write a simple function that would send tokens using a different account action. Exactly the same situation as in these questions: one and two
But I have to use not eosio.token contract but ...
1
vote
1
answer
614
views
How to solve !action_type.empty(): Unknown action hi in contract hello?
I am following this doc: https://developers.eos.io/eosio-home/docs/your-first-contract.
This is the hello.cpp contract code which is successfully deployed:
#include <eosiolib/eosio.hpp>
#...
1
vote
0
answers
102
views
How to solve !action_type.empty(): Unknown action hi in contract hello?
I am following this doc: https://developers.eos.io/eosio-home/docs/your-first-contract.
This is the hello.cpp contract code which is successfully deployed:
#include <eosiolib/eosio.hpp>
#...
1
vote
1
answer
152
views
Smart contract error while calling recover_key
Specs
I am using the function recover_key from the library crypto.h at the following link: https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/crypto.h
Code
int compressed_size = ...
1
vote
1
answer
154
views
how to create an account except the way of using cleos?
guys!I am a beginner of eos.
As it is said on the title, i want to create accounts by the way other than using cleos.
I have traversed the doc of eos, but not seen the interface to create an account ...
0
votes
2
answers
2k
views
Transfer EOS tokens inside a smart contract from an account to another
I want to implement, in my smart contract(C++), a function that forwards EOS token to another account. This is actually a basic question, but is that possible actually? Please, could you share the ...
0
votes
1
answer
97
views
Trouble using EOSIO built in crypto library (can't resolve headers)
I ran eosio-init on the newest CDT (1.7) and made a -bare project.
newtest.cpp
#include "newtest.hpp"
ACTION newtest::hi( name nm ) {
/* fill in action body */
print_f("Name : %\n",nm);
}
...
0
votes
2
answers
1k
views
Convert string to float or double
I am trying to convert a string to a float or double, however none of the standard C/C++ methods seem to work. I have tried:
atof
strtof
strtod
sscanf
In each case, I get an error message when ...
0
votes
1
answer
104
views
Passing struct as a parameter to smart contract action
I want to save data in the blockchain table whose format is as below:
{
"docsample": {
"id": 1,
"creationDate": "2012-05-16T18:25:43.511Z",
"...
0
votes
1
answer
59
views
template function in contract code with a lambda
This is more a C++ question than EOS contracts question but I am having trouble creating a template function for migrating tables to a different scope. I cannot get this to compile.
template <...
0
votes
1
answer
176
views
Passing the action name having return type to EOSIO_DISPATCH in EOSIO smart contract
I have following EOSIO smart contract:
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class random : public contract
{
public:
using contract::...
0
votes
1
answer
138
views
Does permission_level (_self) means that only contract can use this method?
If yes, then how do I make sure that anyone or any specified address can call a method? If not then what is the usage of permission_level (_self ...)?
action{
permission_level{_self, "active"_n}...