I have created a faucet for the NEM testnet. Luckily, there was already some information about NEM written in Japanese, so I was able to start quickly to make the faucet. Thank you to the contributors who translated the information and this blog.
Let me explain about the NEM testnet and its faucet.
What is the NEM Testnet?
It is a peer-to-peer (P2P) network where developers “test” their programs using NEM virtual currencies. Most virtual currencies have an independent value so developers have some risks with testing new apps on the main network. Furthermore, there are some additional chances of other difficulties that means we could effect others on the mainnet.
Since the differences between the testnet and mainnet are only the value of the coins and strength of nodes, programs working on the main net can also work on testnet in the exact same way. And NEM has a more complicated structure with more options than Bitcoin or Counterparty so I strongly recommend that you confirm and test the behavior of your program on testnet before running it on the mainnet.
What is the NEM Testnet Faucet?
It is a faucet by which you will get test XEM (the base currency on NEM) for the testnet. NEM has an ideal environment for developers because there is already a testnet open to everyone and developers are free to run their own node. But before you had to ask the NEM developers to send test XEM in order to run tests. It was inconvenient and slow, so I made the NEM Testnet Faucet. Additionally, there was a bounty from the bounties program to build a faucet.
How to use the NEM Testnet Faucet?
It’s very easy.
Please remember that a testnet address starts with “T”. (I recommend the using the NanoWallet for testing purposes.)
1) Go to this website: http://namuyan.dip.jp/nem/main/index.php
2) Write down your testnet address in the “NEM Address” box
3) Write down any message in the “message” box (Please make a funny one!)
4) Confirm an authentication process via reCAPTCHA and click the “Click!” button
Then you have finished the process and in addition to the test XEM, you’ll get a randomly selected Mosaic asset as well.
Unfortunately, if you create a Mosaic, you need 5000 XEM. It’s hard to click the faucet 50 times, so I will plan to make another way (or contact the NEM developers).
How to use SBM Faucet (SBMF)?
I also made a faucet for Mosaic assets. SBM stands for Small Business Mosaic, and the amount of it is limited 10,000 and it cannot be divided.
1) Send 10 XEM to “TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W” with a message
2) Write down
twistSBMF in a message box
You should see “Complete!” in the Deposit History section and then you will get a randomly selected Mosaic!
How to register your Mosaics on SBMF?
Plus you can register your own Mosaic on the faucet. When your Mosaic is selected, 3XEM on average will be sent to you.
You should be the creator of SBM and meet the SBM requirements
1) Send 10 XEM and your SBM to TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W with the certain message below.
2) Write down
sbmf,namespace:mosaic,[minimum numbers of your SBMF a once],[ maximum numbers your SBMF a once] in the message box. For example,
You should see “Complete!” in the Deposit History section!
Your mosaic assets are now mosaics on the SBMF Faucet.
How to build the faucet
I used PHP and Mysql and referred to the “NEM NIS API Documentation” and “NEM関連サイトまとめ”.
There are two types of transactions actually. Version 1 is specifically for sending only XEM, and Version 2 is for sending Mosaic assets including also XEM. I rewrote the functions to class the method, please refer to this Example.
- timeStamp is not an Unixtime to avoid Year 2038 problem. (It is not certain)
- type represents the type of transaction. Sending is 257. There are some other transactions for importance, creating a mosaic, renting a namespace, multisig edits, etc.
- deadline means the term during which transactions exists on mempool.
- version means a transaction version.
- signer means a public key of the creator of the transaction.
This is how I calculate the fee.
$amount is the amount of sending XEM.
$message is a message. If you don’t want to send any message, don’t bother.
$mosaic is to put a detail of mosaic asset into the array.
Officially the fee calculation is written as:
x = how many mosaics you send
fee = Max(1, Min(25, x * 900_000 / MosaicSupply) - floor(0.8 * ln(9_000_000_000_000_000 / MosaicSupply * 10^divisibility)))
But I wrote:
$initialSupplybyUnit = $DetailMosaic['initialSupply'] * pow(10, $DetailMosaic['divisibility']);
$fee_tmp += round( max(1, min(25, $quantity * 900000 / $initialSupplybyUnit ) - floor(0.8 * log(9000000000000000 / $initialSupplybyUnit ))));
The official way is not wrong but confuses me. There are two notations on the amount.
Without thinking, I made an error with the POST method (eg. /local/account/transfers/incoming )
error：Content type 'application/x-www-form-urlencoded' not supported
When you request POST to NIS, it must be “Content-Type: application/json”.
How To Setup a Faucet
Please refer to the README.md.
git clone https://github.com/namuyan/NEM-testnet-Faucet.git
Make a main folder and copy all data of NEM-testnet-Faucet to the folder.
cp -r /patt/to/NEM-testnet-Faucet/* /passs/too/main/
Match the authority with * htdocs *.
chown -R daemon:daemon htdocs
To fit local environment cron/.htaccess and example/.htaccess. DO NOT ALLOW OTHERS TO ACCESS!
If your local IP is
allow from 192.168.3.0/24→
allow from 192.168.1.12/24
Create NEM account,
curl http://localhost:7890/account/generateDO NOT SHOW OTHERS
Write the three account data ($NEMAddress $NEMprikey $NEMpubkey) to config.php.
Create DB account (Use different parameter to Example. I use same parameter of config.php as example)
１、Login as root
mysql -u root -p
CREATE DATABASE nemdb CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'nember'@'localhost' IDENTIFIED BY 'obama';
４、Grant the user access to the DB
GRANT ALL PRIVILEGES ON nemdb.* TO 'nember'@'localhost';
Create tables After write down to config.php
Example: If makedb.php on htdocs/main/cron/makedb.php, access to
Check no error output.
Run regularly by crontab.
１、To make a pass of $root_dir of Deposit.php ImageReg.php SBMFaucet.php in main/cron.
２、Get pass to type
pwdat main folder.
４、Write down followings. (pass is original)
*/4 * * * * /opt/lampp/bin/php /opt/lampp/htdocs/main/cron/Deposit.php >/dev/null 2>&1
*/5 * * * * /opt/lampp/bin/php /opt/lampp/htdocs/main/cron/ImageReg.php >/dev/null 2>&1
*/6 * * * * /opt/lampp/bin/php /opt/lampp/htdocs/main/cron/SBMFaucet.php >/dev/null 2>&1
Register reCAPTCHA, and write Secretkey to function.php on 17 line.
- When an error message occurs, please check PASS.
I would love to receive your kind donations.
- DonationCPaddress： 1BvRTmPCe47vee2CyrLi9AGeSEcrR2ciM4
- DonationNEMaddress： NAN7XFG52NL3V5AW3NTSYO77AVR6X5LYRJKXWKHY
- DonationMonacoin： MSYTEF7t62b9sjXt3oN9JokSjnYkvtcPFx
The NEM Team would like to thank user Namuyan for creating this blog and project and user Coffetimes for translating it.