Questions tagged [c++]
All questions related to the use of C++ within the EOSIO framework
62
questions
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 = ...
0
votes
1
answer
12
views
Alternative to std::ifstream for eosio contract
I'm watching for an alternative to "std::ifstream" because "#include " can't include as header in a contract.
My code is:
std::istream& operator>>(std::istream& str, ...
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>
#...
0
votes
1
answer
56
views
Runtime error (eos-vm system failure) on using C++ `virtual` keyword?
In my contract I have a data structure that involves a node struct and a LeafNode and InnerNode struct that inherit from node.
struct node {
...
virtual string to_string() const {
...
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
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
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 ...
0
votes
1
answer
143
views
multi_index table get const_iterator at a specific position
is there a better way than a loop to get the value/const_iterator at a specific position in multi_index table?
current:
auto idx = _table.get_index<"name"_n>();
const_iterator b;
int count = ...
0
votes
1
answer
53
views
Nested depth exceeded
kipping set abi because the new abi is the same as the existing abi
Publishing contract...
Error 3070002: Runtime Error Processing WASM
Error Details:
Nested depth exceeded
pending console output:
...
0
votes
1
answer
232
views
How can I create a table in an .hpp for a general contract? (Using the CDT)
THE STRUCTURE OF MY PROJECT
I am working in mycontract.cpp, which imports myheader.hpp
WHAT I WANT
I want to create a table in myheader.hpp, for a generic contract, "IN THEORY" as follows:
struct [...
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 ...
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",
"...
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
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
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
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 = ...
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
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 ...
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 ...
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);
}
...
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?
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"?
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);
}
...
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(...
0
votes
2
answers
107
views
EOS CDT: where are the *.h and the *.cpp files stored in the filesystem, I need reference to them to compile
I'm trying to use the EOS CDT (contract development toolkit).
I've downloaded and installed the repository from github, and used to following commands, as indicated from the eos.io development page.
...
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 ...
0
votes
0
answers
47
views
Catch errors when calling deposit
When I send EOS in a contract to several recipients, it can happen that this fails, e.g. because a recipient has a contract running like that:
Example contract of one recipient:
[[eosio::on_notify("...
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?
0
votes
1
answer
972
views
How to pass a list / array / vector to an action? [duplicate]
I need to pass a list of integers to an action. It would be fine to use vectors or arrays, but I can't find one that works. Using vector in the smart contract compiles fine, but then I get this error ...
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
...
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?
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 ...
0
votes
1
answer
37
views
what are supported STL types in tables?
What are the supported STL types in tables? I'm specifically curious about std::pair
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
196
views
EOSIO: name.value secondary index returns end iterator, even though searched value exists in table
I've got a multi-index table going with two secondary indices:
TABLE entry {
uint64_t id = 0;
eosio::name player;
std::vector<uint16_t> allocation;
...
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 -...
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 ...
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 ...
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 ...
0
votes
0
answers
21
views
Can I deploy a contract from within a contract? [duplicate]
We can create accounts from contract code:
https://github.com/angelol/smart_account_creator
and we can query things about accounts:
https://github.com/nsjames/Account-Has-Code
is there a way to ...
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, ...
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}...
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
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::...
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
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
#...
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>
#...
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 ...
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?