During the course of this short tutorial, we would deploy a Spending Condition to a LeapDAO testnet. Spending condition is a special type of smart contract which runs on Plasma instead of being deployed to main Ethereum chain. Unlike traditional smart contract, output of spending condition should depend only on its input and condition itself should not affect arbitrary state. Following this tutorial would allow you to retrace steps presented in instructional video.
In the course of the tutorial you will need:
- (Optional) Twitter account to get tokens.
- Metamask to hold tokens and sign transactions.
- Truffle or other way of compiling solidity code.
- Node.js to launch deployment script.
Getting LEAP tokens on testnet.
If you already have some LEAP tokens, feel free to skip this step.
- Go to the faucet page. You will need to have access to a twitter account for the next step.
- As instructed on the faucet page, publish a tweet containing your Ethereum address and mention of @leapDAO.
- Insert URL to your tweet on the faucet page, request tokens and go to wallet page.
- Connect metamask on Rinkeby network.
In this part, we would take a look at an example spending condition and compile it.
spending-conditionsrepository or clone it from command line via
git clone https://github.com/leapdao/spending-conditions. Solidity source code for the spending condition that we will interact with is located in
- Build the contract. Easiest way is to use
truffle compilein root folder of the downloaded repository assuming you have truffle installed. Look here for notes on installing truffle framework.
The HashLockCondition we are working with locks money under a hash. Anyone knowing the pre-image of the hash is able to send a transaction and claim the funds. Hashlock conditions can be used to escrow the trade between entities and are base technologies that enable payments and state channels, like the bitcoin lightning network and the ethereum raiden.
We will use a command-line script located at
spending-conditions repository to deploy our condition and interact with it. The source code of the script can be found here.
The script takes two arguments.
hashLockCondition <token address> <message sender address> which would replace
tokenAddr hardcoded in our Spending Condition. To deploy the script simply:
- (Optional) You can set
RPC_URLenvironmental variable like so
RPC_URL=https://testnet-node1.leapdao.orgto ensure your spending condition would be deployed to LeapDAO testnet. If
RPC_URLis not set, the script should be pointed at LeapDAO testnet by default.
- Execute the
tools/hashLockCondition.jsscript. As first argument paste Token contract address displayed on your wallet page. As second argument use your address displayed on wallet page as My address. The script will keep printing
Calling: plasma_unspent [<condition address>]untill it receives transaction that we will sign in the next step.
- Go to your leapDAO wallet page and transfer some amount of LEAP tokens to the address that appears on your command line. You will need to sign transaction using Metamask browser plugin.
Once the spending condition has received your funds, you will see some raw input printed on command line and script will gracefully exit. The final step is to verify if script has indeed submitted both the spending condition and transaction to the LeapDAO testnet:
- Once deployed spending condition receives transaction we signed in deployment step, raw transaction data would be printed to command line.
- In order to see what happened once your transaction was submitted to testnet copy the hash following the string
transaction hash:and paste it into LeapDAO block explorer.
If spending condition has succeeded (as it should in our example, assuming valid
<token address> and
<message sender address> were passed as arguments to the script) block explorer will show a page containing details of the transaction that was submitted.
If wrong argument (such as
<token address> which does not exist on the blockchain) was passed to the script, then explorer would be unable to show transaction details and indicate this with message
No results found for your search.
Spending Conditions, like the one which we just deployed, allow the execution of smart contracts on Plasma. Thanks to moving transactions off main Ethereum chain and into the second layer we can build faster and cheaper Dapps that are not viable on the Ethereum mainnet. With Spending Conditions on Plasma we extend the capabilities of Ethereum in terms of performance and usability beyond Platforms like EOS or TRON.