Skip to content

Commit

Permalink
Update README with challenge instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet authored Jul 11, 2018
1 parent 48cda32 commit 1d2327c
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
# wrc20-examples
# WRC-20 challenge examples

This repository contains examples of WRC20 tokens written in different languages.

## Joining the challenge

Have a look at [this gist](https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363), implement the logic for the following contract (pseudocode) in your favorite language:

```javascript
// main ewasm entry point
function main() {
if (eei_calldatasize() < 4)
eei_revert(0, 0)
let selector = eei_calldatacopy(0, 4)
switch selector {
case 0x9993021a:
do_balance()
case 0x5d359fbd:
do_transfer()
default:
eei_revert(0, 0)
}
}

function do_balance() {
if (eei_calldatasize() != 24)
eei_revert(0, 0)

let address = eei_calldatacopy(4, 20)
// make sure that address is 160 bits here,
// but storage key is 256 bits so need to pad it somehow
let balance = eei_storageload(address)
eei_return(balance)
}

function do_transfer() {
if (eei_calldatasize() != 32)
eei_revert(0, 0)

let sender = eei_sender()
let recipient = eei_calldatacopy(4, 20)
let value = eei_calldatacopy(24, 8)
let sender_balance = eei_storageload(sender)
let recipient_balance = eei_storageload(recipient)

if (sender_balance < value)
eei_revert(0, 0)

sender_balance -= value
recipient_balance += value

eei_storagestore(sender, sender_balance)
eei_storagestore(recipient, recipient_balance)
}
```

Then simply put it in a directory named after your language and send us a PR.

0 comments on commit 1d2327c

Please sign in to comment.