Is now in the development stage.
There is a set of classes and functions in chain.hpp
and contract_base.hpp
for the interaction with the Echo chain.
Member of class account
.
You can get balance of account or contract in needed assets.
Parameters
Option | Description | Example |
| triplet id of account or contract | 1.2.5646 or 1.11.165 |
| triplet asset id | 1.3.0 |
Return
int64_t
- requested balance.
Example
int64_t my_get_balance(string id, string asset_id){account other(id);return other.get_balance(asset_id);}
Member of class contract_base
.
You can transfer assets from contract to the recipient.
Parameters
Option | Description | Example |
| triplet id of account | 1.2.5646 |
| triplet asset id | 1.3.0 |
| transferred amount | 100 |
Return
void
Example
void my_transfer(string to, string asset_id, int64_t amount){transfer(to, asset_id, amount);}
Member of class object
.
You can get property of object from echo chain.
Parameters
Option | Description | Example |
| triplet id of object | 1.2.15 |
| name of property | echorand_key |
Return
string
- value of requested property.
Example
string my_get_property(string id, string request){object other(id);return other.get_property(request);}
Member of class contract_base
.
You can get asset id with which the contract was called.
Return
uint64_t
- asset id with which the contract was called.
Example
uint64_t my_get_call_asset_id(){return get_call_asset_id();}
Static member of class chain
, in the namespace x86_64_contract
.
You can get block hash by number.
Parameters
Option | Description | Example |
| number of block | 15445 |
Return
string
- block hash.
Example
string my_get_block_hash(uint32_t number){return chain::get_block_hash(number);}
Member of class contract_base
.
You can get the author of current block.
Return
string
- block author id.
Example
string my_get_block_author(){return get_block_author();}
Member of class contract_base
.
You can get current gas limit.
Return
uint64_t int
- current gas limit in 10^-8^ ECHO.
Example
uint64_t int my_get_gas_limit(){return get_gas_limit();}
Member of class contract_base
.
You can get current head block number.
Return
uint32_t
- block number.
Example
uint32_t my_get_block_number(){return get_block_number();}
Member of class contract_base
.
You can get current head block timestamp.
Return
uint32_t
- block timestamp in seconds.
Example
uint32_t my_get_block_timestamp(){return get_block_timestamp();}
Member of class contract_base
.
You can get send value for current contract call.
Return
int64_t
- amount of send.
Example
int64_t my_get_send_value(){return get_send_value();}
Member of class contract_base
.
You can get sender for current contract call.
Return
string
- triplet id of sender.
Example
string my_get_sender(){return get_sender();}
Member of class contract_base
.
You can get origin sender for current contract call.
Return
string
- triplet id of sender.
Example
string my_get_origin_sender(){return get_origin_sender();}
Static member of class chain
, in the namespace x86_64_contract
.
You can get called contract id.
Return
uint32_t
- id of contract.
Example
uint32_t my_get_contract_id(){return chain::get_contract_id();}
Member of class contract_base
.
You can get full contract id.
Return
string
- triplet id of contract.
Example
string my_get_full_contract_id(){return get_full_contract_id();}
Member of class contract_object
.
You can call get storage variable from another x86-64 contract. For the get, you will need to pass the amount by 0, count of gas by 0 and the variable name.
Parameters
Option | Description | Example |
| triplet id of contract | 1.11.165 |
| amount, doesn't affect anything | 0 |
| gas, doesn't affect anything | 0 |
| variable name | "var_name" |
Return
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
Example
void call_contract(string id, string var_name, uint64_t amount, uint64_t gas){contract_object c(id);string var_1 = c.call(amount, gas, var_name);string var_2 = c.call(amount, gas, string("var_name"));}
Member of class contract_object
.
You can call another x86-64 contract. For the call, you will need to pass the amount, count of gas to perform and the call line. If you do not want to limit the call to the gas, 0 is transmitted.
Parameters
Option | Description | Example |
| triplet id of contract | 1.11.165 |
| amount allocated to the contract, in the smallest units | 0 or 1000000 |
| gas restriction for internal call, if you set 0, then there will be no limit | 0 or 10000000 |
| call line | greet() or get_balance(\"1.2.236\", \"1.3.0\") |
Return
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
Example
string call_contract(string id, string call_line, uint64_t amount, uint64_t gas){contract_object c(id);return c.call(amount, gas, call_line);}
Member of class contract_object
.
You can call another x86-64 contract. For the call, you will need to pass the amount, count of gas to perform, callee function name and the call params. If you do not want to limit the call to the gas, 0 is transmitted.
Parameters
Option | Description | Example |
| triplet id of contract | 1.11.165 |
| amount allocated to the contract, in the smallest units | 0 or 1000000 |
| gas restriction for internal call, if you set 0, then there will be no limit | 0 or 10000000 |
| callee function name | get_balance |
| call params | a, true, 637, string("string_param") |
Return
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
Example
string call_contract(string id, string var_1, unsigned int var_2, uint64_t amount, uint64_t gas){int var_local = 544;bool var_bool = true;​contract_object c(id);return c.call(amount, gas, string("my_function"), var_1, var_2, var_local, var_bool, -45);}
#include "chain.hpp"#include "contract_base.hpp"#include "db_types.hpp"#include "parameters.hpp"#include "string.hpp"​namespace x86_64_contract {​class contract : public contract_base{public:void send_to_contract(){_value += get_send_value();}​bool transfer(string to, string asset_id, uint64_t amount){string sender = get_origin_sender();uint64_t send_with_call = get_send_value();​object sender_obj(sender);string sender_name = sender_obj.get_property("name");​if (sender != _owner && sender_name != "my_second_account"){if (send_with_call < amount)return false;else{transfer(to, asset_id, amount);_value += send_with_call - amount;return true;}}​if (_value + send_with_call < amount)return false;​transfer(to, asset_id, amount);_value += send_with_call - amount;return true;}​void constructor() override{_owner = get_origin_sender();}​private:string _name { "my_contract" };DB_STRING(_owner);DB_UINT64(_value);};​MAIN(contract, FUNC(send_to_contract) FUNC(transfer))​}