Plasma consists of three major parts.
- Plasma chain: A simple proof-of-authority chain where the actual transactions take place.
- Plasma contract: A smart contract deployed on root chain which handles the deposits and withdrawals for the child chain (plasma chain).
- Ethereum blockchain: The root chain which only records the block headers of the plasma chain.
The complete cycle of interacting with plasma is made up of three stages.
Participants deposit to the plasma contract on the root chain. Then the operator at the plasma chain will construct a deposit transaction according to the contract event when building a new block.
Participants could transact with each other on the plasma chain without notifying the root chain. Only when every block is created by the operator, it will submit the block header to the plasma contract on the root chain.
A withdrawal is initiated by calling the plasma contract. After creating a withdrawal, user needs to wait 7 days for other participants to challenge it. If anyone could prove the given withdrawal that has been spent later on the plasma chain, the withdrawal will be canceled. Otherwise, after 7 days and without any other withdrawals with higher priority, user could withdraw his funds back to the root chain.
- Launch an Ethereum private chain as the root chain.
- Deploy the plasma smart contract on the root chain manually.
- Set the contract address at config file (config.js).
- Create accounts on Ethereum blockchain for the operator and participants.
npm install
HTTP_PORT=3001 npm start
Get the whole blockchain.
None
curl http://localhost:3001/blocks
Miner mines a new block.
None
curl -X POST http://localhost:3001/mineBlock
Create a transaction to other participants. User could specify at most two UTXOs to spend. Also note that the units used in field amount
is ether.
Name | Type | Required | Description |
---|---|---|---|
blkNum1 | Integer | Yes | First UTXO position |
txIndex1 | Integer | Yes | First UTXO position |
oIndex1 | Integer | Yes | First UTXO position |
blkNum2 | Integer | No | Second UTXO position |
txIndex2 | Integer | No | Second UTXO position |
oIndex2 | Integer | No | Second UTXO position |
newOwner | Address | Yes | Transfer funds to whom |
amount | Decimal | Yes | How much ether (in ether) |
from | Address | Yes | Transfer funds from whom |
curl -H "Content-type:application/json" --data '{"from": "0xC973531975B1EE371164DCcB9529b89A7bCD1c4A", "blkNum1": 4, "txIndex1": 1, "oIndex": 0, "newOwner": "0x52A6d6c37648Fb1bCd3c641DF3DB35F12a87C4fc", "amount": 0.05}' http://localhost:3001/transact
Deposit funds to Plasma smart contract.
Name | Type | Required | Description |
---|---|---|---|
address | Address | Yes | Deposit from whom |
amount | Integer | Yes | How much funds to deposit |
curl -H "Content-type:application/json" --data '{"address": "0xC973531975B1EE371164DCcB9529b89A7bCD1c4A", "amount": 0.2}' http://localhost:3001/deposit
Create a new withdrawal.
Name | Type | Required | Description |
---|---|---|---|
blkNum | Integer | Yes | The position of the UTXO user wants to withdraw |
txIndex | Integer | Yes | The position of the UTXO user wants to withdraw |
oIndex | Integer | Yes | The position of the UTXO user wants to withdraw |
from | Address | Yes | The owner of the UTXO |
curl -H "Content-type:application/json" --data '{"blkNum": 3, "txIndex": 1, "oIndex": 0, "from": "0xC973531975B1EE371164DCcB9529b89A7bCD1c4A"}' http://localhost:3001/withdraw/create
Create a withdrawal challenge.
Name | Type | Required | Description |
---|---|---|---|
withdrawalId | Integer | Yes | The withdrawal ID user wants to challenge |
blkNum | Integer | Yes | The position of the UTXO user wants to challenge |
txIndex | Integer | Yes | The position of the UTXO user wants to challenge |
oIndex | Integer | Yes | The position of the UTXO user wants to challenge |
from | Address | Yes | The owner of the UTXO |
curl -H "Content-type:application/json" --data '{"withdrawalId": 4000000000, "blkNum": 4, "txIndex": 2, "oIndex": 1, "from": "0xC973531975B1EE371164DCcB9529b89A7bCD1c4A"}' http://localhost:3001/withdraw/challenge
Finalize withdrawals manually.
Name | Type | Required | Description |
---|---|---|---|
from | Address | Yes | Who initiates the withdrawal finalization |
curl -H "Content-type:application/json" --data '{"from": "0xC973531975B1EE371164DCcB9529b89A7bCD1c4A"}' http://localhost:3001/withdraw/finalize