Smart contract backing a hypothetical ledgr.link URL shortener service.
Ledgerlink (or ledgr.link) is a hypothetical URL shortener service that uses the NEO blockchain as a mean to store irreplaceable / unfalsifiable short URLs. Such shortened URLs are protected against any third party interferences because they cannot be changed by anybody - they will live forever on the NEO blockchain. Thus the NEO blockchain is used as a source of trust, ensuring that the shortened links always lead to where they are supposed to.
This repository embeds the smart contract used by this URL shortener service. This smart contract provides a secure way of generating shortened-URLs and storing the related uniques codes into the NEO blockchain. It is written in Python and makes use of the neo-boa compiler.
Table of Contents
You can install the project locally using the following commands:
$ git clone https://github.com/ellmetha/ledgerlink-contract && cd ledgerlink-contract
$ pipenv install --dev --python /usr/bin/python3.5 # or any other valid path
Once all the dependencies have been installed, you can trigger the compilation of the smart contract using the following command:
$ make avm
The resulting ledgerlink.avm
file will be stored under the ./build
directory.
You'll need a working Docker installation in order to set up such privnet. The first thing to do is to pull a Docker image containing a working NEO privnet and a wallet associated with a convenient amount of GAS.
$ docker pull metachris/neo-privnet-with-gas
$ curl https://s3.amazonaws.com/neo-experiments/neo-privnet.wallet -o /tmp/neo-privnet.wallet
You can now start up the privnet using the following command:
$ docker run -d --name neo-privnet-with-gas -p 20333-20336:20333-20336/tcp -p 30333-30336:30333-30336/tcp metachris/neo-privnet-with-gas
You now pull the latest version of neo-python and start the node with PrivNet configuration using:
$ git clone https://github.com/CityOfZion/neo-python
$ python prompt.py -p
At this point it should possible to open the pre-configured wallet, deploy the compiled version of the smart contract and start interacting with it:
# Open the wallet ; password is: coz
neo> open wallet /tmp/neo-privnet.wallet
[password]> ***
Opened wallet at /tmp/neo-privnet.wallet
# Rebuild wallet and associated assets.
neo> wallet rebuild
# Deploy the compiled AVM version of the ledgerlink contract.
neo> import contract /path/to/ledgerlink-contract/build/ledgerlink.avm 0710 01 True False
contract properties: 1
Please fill out the following contract details:
[Contract Name] > ledgerlink
[Contract Version] > 1
[Contract Author] >
[Contract Email] >
[Contract Description] >
Creating smart contract....
Name: ledgerlink
Version: 1
Author:
Email:
Description:
Needs Storage: True
Needs Dynamic Invoke: False
# Wait for the contract to be persisted to the blockchain... and retrieve the hash script of the
# contract using the search command.
neo> contract search ledgerlink
# Invoke the smart contract in order to add a new URL
neo> testinvoke <scriptHash> addURL ['https://neo.org'] --attach-gas=0.001
# Wait for the transaction to be confirmed and copy the generated code from the logs.
# It should now be possible to retrieve the URL using the code with the following invocation.
neo> testinvoke <scriptHash> getURL ['<code>'] --attach-gas=0.001
MIT. See LICENSE
for more details.