# 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:

{% code title="demo.hpp" %}

```cpp
#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>;
   };
}
```

{% endcode %}

{% code title="demo.cpp" %}

```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 );
};
```

{% endcode %}

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>*)

```bash
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 <mark style="color:red;">mandatory</mark> to put the word *<mark style="color:red;">**contract**</mark>* before the account name (see example above).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sp8de-docs.gitbook.io/s-p-8-d-e-or-white-paper/smart-contract-user-funct./buy-quant-random/redirecting-the-result-to-the-user-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
