Advertising Link Exchanger on Emercoin


emcLNX is a peer-to-peer text-advertisement network based on a per-click payment model. There are 3 roles in this system:

  • Buyer: Advertises their website using the emcLNX network. They pay a small amount of funds for each Visitor referred to their site by the emcLNX network.
  • Host: Displays emcLNX advertisements on their website. When a Visitor clicks an ad, the Host sends this Visitor to the Buyer's website and receives payment from the Buyer for this visit.
  • Visitor: An ordinary web-user who clicks on an advertisement on the Host's website and arrives at the Buyer's website.

An emcLNX participant can be Buyer and Host at the same time, i.e. they can show advertising links on their website, and also purchase traffic (visits) from the emcLNX network. Hence, they can pay other participants to attract visitors to their site, while earning money for sending visitors to other sites.

The system is completely decentralized and therefore is censorship resistant and cannot be shut down. In this system, a Buyer directly pays the Host for each Visitor, i.e. there is no central agent to set a minimum price, allowed words, etc. Also, there is no "participation fee" or commission - all payments go directly between Buyers and Hosts, without the involvement of any intermediate agent.

emcLNX runs on the Emercoin cryptocurrency and uses it in two ways:

  • It uses Emercoin credits (EMC) as the payment unit for pay-per-click actions.
  • It uses Emercoin Name-Value Storage (NVS) as distributed storage for advertising contracts.

Download and install

First, you need to be running a php-enabled web-server with MySQL. This is a common part of modern websites, so we will skip installation manuals for these parts and assume you already have this running.

Second, you need to download and install the Emercoin wallet daemon, emercoind. You can download it here: http://sourceforge.net/projects/emercoin/files/

The tutorial http://emercoin.com/VPS_SETUP_GUIDE covers how to install emercoind on a VPS.

emcLNX uses the RPC interface, so pay attention to the config parameters related to RPC access: rpcuser, rpcpassword, rpcport, rpcallowip.

After successful emercoind start, download and unzip the emcLNX archive: http://www.emercoin.com/files/emclnx-0.0.6.tar.gz

After unzip, there will be two subdirectories:

  • emclnx-0.0.6/emclnx - for website modules
  • emclnx-0.0.6/adm - for administrative/setup tools

Go to the /adm directory to perform some initial operations:

  1. Create a username and the database for emcLNX. The file emclnx_create_db.sql contains the appropriate commands. Just substitute default password 12345 with something secure.

  2. Edit the script create_tables.sh, by changing default password 12345 to the password you used above. Now run this script. This script will create database tables for emcLNX.

  3. Edit the file emclnx-config.php to modify the following lines, to set your password and config params for your system:

    'url'     => "http://user:[email protected]:8774";,
    'db_pass' => "12345",
    'dest_url'   => "http://www.emercoin.com/";,

    The last parameter contains the URL for your site, where referred users will be directed. Refer to the emclnx-config.php file itself for more information and options.

  4. From your www directory, make a symbolic link to the emclnx directory that you unzipped earlier. This is needed so that www users can run php scripts located in the emclnx directory. The destination link must be absolute. Paths for your system can differ but the command should be similar to this:

    ln -s /home/root/emclnx-0.0.6/emclnx /var/www/emclnx

  5. In addition, you need to create a log file, and allow the www user write access to it. To do this, run commands similar to:

    touch /var/log/emclnx.log
    chown www /var/log/emclnx.log


To start hosting advertisements, you will need to edit the file emclnx/emclnx-config.php

First, modify sections keywords, langs, country, and min_cpc. See comments for appropriate parameters.

Next, you need to import advertising contracts from the Emercoin NVS into your local database, and assign them priorities. To do this, just go to emclnx-0.0.6/adm and run:


Next, go to the emclnx symlink directory, with the appropriate command, e.g.:

cd /var/www/emclnx

and run the program user_page.php:

php ./user_page.php

If everything is OK, the program will print a link from a random advertising contract.

The program code is simple; you should review it and then integrate it into your website.

After integrating the code into your website, visit your site from the internet and confirm that your page contains an emcLNX advertisement link. Click it... and you will earn a small amount of Emercoin!!!

Don't click too quickly or often. The system can detect fraudulent behavior, and Buyers will ban you!

Note: It's a good idea to run ./fetch_contracts.php from crontab daily (or even hourly), to automatically import new contracts.


To use emcLNX as a Buyer, you need to deposit some EMC into your emercoind wallet - the system will use these funds to pay Hosts for Visitors who are referred to you. You can purchase EMC on an exchange or mine them with a mining pool. See info at: http://www.emercoin.com

In addition, you need a separate GUI-enabled Emercoin wallet to manage advertisement contracts and signatures. Of course, if needed, you can use a single wallet for both functions, but it's more practical to use two independent wallets - one for payment, another for contract management.

  1. In the GUI-wallet, generate a new address, and deposit this address into the domain record's TXT field (regular ICANN or emcDNS), for the site you plan to advertise, in the following format:


    For example, see dig output for domain emercoin.com:
    $ dig emercoin.com TXT | grep emclnx
    emercoin.com.   243     IN      TXT     "emclnx=EdvJ7b7zPL6gj5f8VNfX6zmVcftb35sKX2"
    It is OK if multiple Hosts or contracts use the same address.

    Next, select some unique name for your contract, for example: MyFirstContract. You will need to check if this name is already allocated to someone else. To do this, go to the GUI-wallet's debug window and enter the command:

    name_show lnx:MyFirstContract

    If you see an error message that the name was not found, then everything is OK (the name is not allocated yet).

  2. Next, generate a signature for your contract with wallet debug command:

    signmessage EMC_ADDR ContractName

    Use the EMC_ADDR you deposited into Emercoin NVS DNS-record above. e.g.:

    signmessage EdvJ7b7zPL6gj5f8VNfX6zmVcftb35sKX2 MyFirstContract

    The wallet returns a signature, like:
    This is the signature for your new contract. This signature is proof that this contract came into the system from you (domain owner), not from a bad actor.

  3. Now, create an advertising contract with a text editor. See the following example contract and explanation:
    SIGNATURE= H1XLT7lj1UUIfsdUxr9uE5EZz0sCYcjBnLivrgdOeDTIQGa2D27KHwH4=
    KEYWORDS=emercoin|cryptocurrency mining|name-value storage
    TXT=Emercoin - Innovative cryptocurrency
    TXT=Emercoin - Innovative distributed blockchain services
    TXT=Emercoin - Distributed uncensored alternative DNS
    TXT=Emercoin - Decentralized security solutions
    TXT=Emercoin - Cryptocurrency with a strong fundamental base
    URL=URL of the program lnx_pay on your website. You can rename this program, or write your own version which does additional things - for example, collecting statistics. The question mark at the end of the URL is just to separate CGI-parameters. If your domain name includes non-ASCII code, the URL must be encoded into IDN/Punny code.

    SIGNATURE=Signature, generated above. Confirms this contract is valid for your specific domain.

    LANG=Contract language (must be single). If you run a multilingual site, and need ads for many languages, generate separate contracts for ads in each language.

    COUNTRY=This is an optional field. If used, your ads will run in specified countries only. If omitted there are no country limits.

    KEYWORDS=Keywords that can help the host's scripts to make better decisions about which advertiements to display. Keywords on the same line are separated by | and multiple lines can be defined.

    CPC=Cost Per Click - how many EMC you will pay to the Host for each Visitor (actual amount can be less, if you (the Buyer) and the Host do not have good "credit history" yet).

    TXT=These are the text strings for the advertisements. Strings are randomly shown on Host's websites, shown one per exposure. Multiple TXT lines can be defined as shown in the example.

  4. Upload your contract into your local database, for your payment system to accept payment requests for this contract. To do this, run the following from the adm directory:

    ./uplo_contract.php CONTRACT_NAME CPC

    For example:
    ./uplo_contract.php MyFirstContract 3.00

  5. Publish your contract to the Emercoin NVS. To do this, go to the "Manage names" tab in the GUI-wallet. Into the "name:" field enter your contract name with service prefix "lnx:", for example: lnx:MyFirstContract. Into "value:", copy/paste your contract. During the paste process the wallet's GUI automatically converts non-ASCII symbols to UTF-8. Alternatively, you can use the "Import" button in the GUI. In this case, be sure your file is saved with US-ASCII charset, or UTF-8. Set the "days:" field to the appropriate time for your contract's lifespan. Finally, click "Submit"... and wait for visitors!!!

How the system works

Buyer creates a contract, including signature, and publishes it in the Emercoin NVS - distributed storage system. The contract is distributed over the EMC network.

Host extracts a random contract from his local db, with call GetRand_href() in the file user_page.php. The probability of extracting a specific contract depends on contract priority, which depends on the CPC, keywords, language and country parameters in the contract.

When a contract is extracted, the system generates a link to the local program lnx_ref.php, with single CGI-parameter - contract name. The format is:

<a href='/emclnx/lnx_ref.php?MyFirstContract>advertising text here</a>

When a Visitor clicks this link, the program lnx_ref.php is invoked with the contract name parameter. The program extracts the contract from the local db, and parses it. It verifies the domain signature, and if OK - it forwards the Visitor to the URL specified in the contract. The URL must refer to lnx_pay.php, located on the Buyer's site. As a CGI-parameter, lnx_ref.php sends an invoice in the format:


For example:

On the Buyer's side, lnx_pay.php validates the contract, checks the balance, invoice, etc, and if everything is OK, it pays for this click. Pay attention to the last value - credit (-0.06). If this value is positive, this means that the Host trusts the payer, and does not require payment instantly. Credit can grow, during a continued relationship between this Host and Buyer. So, if both behave fairly then payments will be less frequent, and the payment amount per transaction is increased.

The system deters new Hosts from behaving badly: when a new Host sends an invoice to the payer, they can request only ~5% of the CPC amount. Over time, as the Buyer becomes assured of honest Host behavior, the maximum invoice value goes up, closer to the contract CPC.

Context links

There is an interesting way to use context links on a CPC basis. As you see above, lnx_ref.php receives a single CGI-parameter - contract name. It doesn't matter where the link is placed. Thus, you can link to your instance of the lnx_ref.php site on a 3rd party blog, forum signature, or another website. Any Visitor clicking this link, will go to your referrer, and your referrer will charge Buyer for the click value.

Bot mitigation

It is necessary to prevent web crawlers (e.g. google) from following emcLNX links, and so hosts should take several precautions:

  1. robots.txt

    Hosts should specify that search engines do not index the /emclnx directory in their website's robots.txt as follows:
    User-agent: *
    Disallow: /emclnx/

  2. Robot trap

    To help defeat bots which ignore the robots.txt, hosts should also include a hidden link somewhere on their page, that leads to the robotrap.php that is included with the emcLNX archive. For example:

    <font size="1%"><a href="emclnx/robotrap.php">&#21;</a></font>

    The above link is not visible to humans since it contains only a non-printable symbol, but a bot will follow it, and their IP address will subsequently become banned by the emcLNX system. Please, don't click the link yourself, otherwise your IP will be banned.


  1. Is there a website already which shows example advertisements?

    Yes! There is a test page on emercoin.com: http://emercoin.com/emclnx/user_page.php
    And cryptor: https://cryptor.net (see gray ad line on top of page).

  2. If a Buyer does not pay, what happens? Will the system prevent their advertisements from being shown?

    Yes. There are several fraud protection measures in the code. If buyer does not pay, the host simply does not show their ads. The buyer is identified by their domain, so they cannot easily create new domains to fool the system. Analogously, a "credit level" is maintained for hosts. If a host tries to "click out" ads, then the buyer will automatically stop paying this host.

  3. What is the software license for the emcLNX php code?

    The code is, of course, open souce, and can be freely used by anyone - just like emcSSL, emcSSH and Emercoin itself.

  4. My site is located behind CloudFlare or another service - how do I ensure payment requests are processed correctly?

    CloudFlare and similar services cache pages, and if a request comes to lnx_pay.php, they may return a cached value. As a result, the Buyer does not pay for referrals, and their link will become banned by other participants.

    CloudFlare provides a solution here. According to this solution, you can exclude certain urls from CloudFlare's caching, and set up a rule to bypass the cache for emcLNX related links. e.g. *emercoin.com/emclnx/*.php -> Bypass cache

    Please take steps to avoid this problem, which can occur with any kind of server-side caching!