Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Add #6 to README
  • Loading branch information
HZ authored Sep 4, 2019
1 parent 7dd149e commit bd3573e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,57 @@ and select the specific node version.
## Demo Screen

![image](https://github.com/cennznet/spin2winApp/blob/master/resources/demo.gif)


## Play with Contract

#### 1. Build and deploy the contract
You can follow this doc to Build and deploy the contract: [spin2win](https://cennznetdocs.com/CENNZNet/tutorials/spin2win.md).

#### 2. Contract address and ABI file
After you build and deploy the contract you will get two items to be used in the next step:
- [Contract address](https://github.com/cennznet/spin2winApp/blob/master/src/services/network.js)
- [Contract ABI json file](https://github.com/cennznet/spin2winApp/blob/master/src/services/Spin2Win.json)

For `Contract ABI` of spin2win:

```json
"messages": [{
"name": "spin",
"selector": 2121348255,
"mutates": false,
"args": [{
"name": "player",
"type": "AccountId"
}],
"return_type": null
}]
```

You will see there is only one method in the contract, and the method name is `spin`, and only one parameter for `spin`, the type is `AccountId`.

#### 3. Call contract

#### [Construct a ContractABI instance](https://github.com/cennznet/spin2winApp/blob/master/src/services/spin2win.js):
You can use this instance to call any messages in the contract ABI file with the correct args. The function will return a `payload` (hex value), this signature includes all the information of the message.

#### [Create transaction](https://github.com/cennznet/spin2winApp/blob/master/src/services/sendReward.js):

Creating [`api`](https://github.com/cennznet/spin2winApp/blob/7dd149e770ccd66bd4bced4e93d45e21cb6fcb35/src/services/cennz-lib.js#L25) and [`set signer`](https://github.com/cennznet/spin2winApp/blob/7dd149e770ccd66bd4bced4e93d45e21cb6fcb35/src/services/sendReward.js#L41).

Calling `api.tx.contract.call` to get `tx` object:
```javascript
const tx = api.tx.contract.call(
contractAddress,
endowment, // deposit amount, can be 0: BigNumber
200000, // gas fee
payload // the payload when calling specific message
);
```
The last step: [`sign and send the tx`](https://github.com/cennznet/spin2winApp/blob/7dd149e770ccd66bd4bced4e93d45e21cb6fcb35/src/services/sendReward.js#L62). You can get the transaction status and all the event details inside the code and also check them on [CENNZnet UI](https://cennznet.js.org/cennznet-ui/#/explorer/query) with `block hash`.

#### 4. Common issues

- The signer should have enough funds to sign a transaction. You can get tokens through [faucet](https://cennznet.js.org/faucet-ui/).
- The network(Localhost or Rimu) of deploying contract and calling contract should be the same one.
- For spin2win contract, should make sure the contract has enough funds to allocate assets. You can also top up the contract, using contract address, through [faucet](https://cennznet.js.org/faucet-ui/).

0 comments on commit bd3573e

Please sign in to comment.