Redirecting the result to the user contract

To redirect the result to the user's contract, the following code should be added to the contract:

demo.hpp
#pragma once

#include <string>
#include <eosio/eosio.hpp>
#include <eosio/singleton.hpp>

namespace eosio {
   using std::string;

   class [[eosio::contract("eosio.demo")]] demo: public contract {
      public:
         using contract::contract;

         [[eosio::action]]
         void result( const name &payer, const name &owner_random_value, const string& random_value );
         using result_action = eosio::action_wrapper<"result"_n, &demo::result>;

      private:
         struct [[eosio::table]] randresult {
            name   owner_random_value;
            string random_value;
         };
         using random_result = eosio::singleton<"randresult"_n, randresult>;
   };
}
demo.cpp
#include <eosio.demo/eosio.demo.hpp>

using namespace eosio;

void demo::result(const name &payer, const name &owner_random_value, const string& random_value )
{
    require_auth( payer );
    require_auth( "quant.random"_n );

    random_result random_result_table( get_self(), payer.value );
    random_result_table.set( {owner_random_value, random_value}, payer );
};

When buying a random, enter the name of your account where the smart contract is located in the memo field (<account name for result forward>)

cleos -u <address node> push action quant.token transfer '["<sender>", "quant.random", "amount QRNG with config", "<cleos -u <address node> push action quant.token transfer '["<sender>", "quant.random", "amount QRNG with config", "contract testaccount"]' -p <sender>>"]' -p <sender>

It is mandatory to put the word contract before the account name (see example above).

Last updated