Anyone is working on some ICO/Payment contacts?
What I would like to learn are following functionalities within the contract:

  1. Payment, where the fee is split into 3 accounts.

    a) So user sends a fee in some token (defined in separate contract), there is a check if the balance is positibe, and then fee is divided and send to three accounts.

  2. A user sends EOS (SYS) token and receives application token with a given exchange rate

  3. The transaction can be executed only within certain time frames. If not then it is rejected.

Any github sample to share?

1 Answer 1


Look at this example:


Hope it will help you

#include <eosiolib/eosio.hpp>
#include <eosiolib/currency.hpp>

using namespace eosio;

class hello : public eosio::contract {
      using contract::contract;

      hello(account_name self) : contract(self) {}

      /// @abi table 
      struct account {
        account_name owner;
        uint64_t balance;

        uint64_t primary_key() const { return owner; };

      typedef eosio::multi_index<N(account), account> accs; 

      /// @abi action 
      void addbalance(account_name owner, uint64_t amount) {
         accs accounts(_self, owner);
         auto existing = accounts.find(owner);

         if (existing == accounts.end())
            /* Add new account */
            accounts.emplace(_self, [&](auto& a) {
                a.owner = owner;
                a.balance = amount;
         } else {
            /* Update existing account */
            const auto& st = *existing;
            accounts.modify(st, 0, [&](auto& a) {
                a.balance += amount;

      void on(const currency::transfer& t) {
        if (t.to == _self) {
            addbalance(t.from, t.quantity.amount);

      void use(account_name contract, account_name act) {
        if (act == N(transfer)) {

        auto& thiscontract = *this;
        switch( act ) {
            EOSIO_API( hello, (addbalance));

extern "C" {
   [[noreturn]] void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
      hello  h( receiver );
      h.use( code, action );
  • I would like to Update this code to CDT 1.5 or CDT 1.6. What I need change ?
    – Efraim
    May 27, 2019 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.