forked from Web3N3/web3-course
Compare commits
2 commits
1eb1468068
...
a743337632
Author | SHA1 | Date | |
---|---|---|---|
a743337632 | |||
8bd839047e |
4 changed files with 149 additions and 105 deletions
105
l6/README.md
105
l6/README.md
|
@ -1,105 +0,0 @@
|
|||
## Prerequisites
|
||||
|
||||
To run this example we will need:
|
||||
|
||||
* Wallet with sufficient GAS on it. In our example we will be using wallet with address `NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW`.
|
||||
* Instance of frostfs-aio running with oracle enabled.
|
||||
|
||||
## Running the example
|
||||
|
||||
In this section we will assume that:
|
||||
|
||||
* Our wallet is located next to `web3-course` directory.
|
||||
* We run all commands in directory `l6`.
|
||||
|
||||
### 1. Compile contracts
|
||||
|
||||
To compile the contracts we run the following commands:
|
||||
|
||||
```sh
|
||||
$ neo-go contract compile -in lottery/lottery_contract.go --config lottery/config.yml --out lottery/lottery.nef --manifest lottery/config.json
|
||||
|
||||
$ neo-go contract compile -in player/player_contract.go --config player/config.yml --out player/player.nef --manifest player/config.json
|
||||
```
|
||||
|
||||
### 2. Assign contracts to the group
|
||||
|
||||
Now we will create a wallet for a group that will contain both contracts. It is possible to skip this step and use wallet `frostfs-aio/morph/node-wallet.json`, but for the sake of purity it is recommended to use a separate wallet.
|
||||
|
||||
To create a wallet, we run the following command. When prompted, enter any name for the account, we will use `l6-game` as group name for this example:
|
||||
|
||||
```sh
|
||||
$ neo-go wallet init -w ../../group-wallet.json -a
|
||||
Enter the name of the account > l6-game
|
||||
Enter new password >
|
||||
Confirm password >
|
||||
```
|
||||
|
||||
Copy account address from the command's output, we will need it in a moment:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"accounts": [
|
||||
{
|
||||
"address": "NgdcCGcR7QveKn9yjQgpemtgtn5zLn33b6", <-- NOTE: take this value
|
||||
...
|
||||
```
|
||||
|
||||
Now we need to assign group to contracts' manifests with the following commands (pay attention that sender is address of our wallet with GAS, but --wallet and --address are referring to the group wallet that we've just created):
|
||||
|
||||
```sh
|
||||
$ neo-go contract manifest add-group -n lottery/lottery.nef -m lottery/config.json --sender NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW --wallet ../../group-wallet.json --address NYThT8RYFhkBzJfzMwCe67A63p2WoDev9X
|
||||
|
||||
$ neo-go contract manifest add-group -n player/player.nef -m player/config.json --sender NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW --wallet ../../group-wallet.json --address NYThT8RYFhkBzJfzMwCe67A63p2WoDev9X
|
||||
```
|
||||
|
||||
Now our contracts are ready to be deployed.
|
||||
|
||||
### 3. Deploy contracts
|
||||
|
||||
Now we can deploy lottery contract:
|
||||
|
||||
```sh
|
||||
$ neo-go contract deploy -r http://localhost:30333 -w ../../wallet.json --in lottery/lottery.nef --manifest lottery/config.json
|
||||
```
|
||||
|
||||
Copy contract hash from the command output and convert it to LE address, for example:
|
||||
|
||||
```sh
|
||||
...
|
||||
Contract: 8b81042613a3df06b4ed0479407ab5107a4a7aaf
|
||||
|
||||
$ neo-go util convert '8b81042613a3df06b4ed0479407ab5107a4a7aaf'
|
||||
BE ScriptHash to Address NYdbfd7nqhPCuS9dBhQKYkr8u1UKCnJykp
|
||||
LE ScriptHash to Address NbuowFNug7QCPM3zYc8HGH5ZsWbHBdGLR9 <-- NOTE: take this value
|
||||
...
|
||||
```
|
||||
|
||||
Now we can deploy player contract, it takes hash of lottery contract as a parameter to its' _deploy method:
|
||||
|
||||
```sh
|
||||
$ neo-go contract deploy -r http://localhost:30333 -w ../../wallet.json --in player/player.nef --manifest player/config.json [ hash160:NbuowFNug7QCPM3zYc8HGH5ZsWbHBdGLR9 ]
|
||||
```
|
||||
|
||||
Copy hash of the player contract from the command's output to use it in the next sections:
|
||||
|
||||
```sh
|
||||
...
|
||||
Contract: e7e4910b3a83ce0eff180a3f5462030391fde830 <-- NOTE: take this value
|
||||
```
|
||||
|
||||
This time we won't need to convert it to any other format and will be able to use it "as is".
|
||||
|
||||
### 4. Create a new player
|
||||
|
||||
To create a new player, invoke `newPlayer` function on the player contract and specify name of the player. In example below we create a player with the name `demo`:
|
||||
|
||||
```sh
|
||||
neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json e7e4910b3a83ce0eff180a3f5462030391fde830 newPlayer string:demo
|
||||
```
|
||||
|
||||
```sh
|
||||
neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 8d099cb315c03c1f040d8912f1f2a84e569ca50c buyItem string:demo string:Shortbow -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:None'
|
||||
```
|
||||
|
149
l6/docs/README.md
Normal file
149
l6/docs/README.md
Normal file
|
@ -0,0 +1,149 @@
|
|||
## Prerequisites
|
||||
|
||||
To run this example we will need:
|
||||
|
||||
* Wallet with sufficient GAS on it. In our example we will be using wallet with address `NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW`.
|
||||
|
||||
## Running the example
|
||||
|
||||
In this section we will assume that:
|
||||
|
||||
* Our wallet is located next to `web3-course` directory.
|
||||
* We run all commands in directory `l6`.
|
||||
|
||||
### 1. Compile contracts
|
||||
|
||||
To compile the contracts we run the following commands:
|
||||
|
||||
```sh
|
||||
$ neo-go contract compile -in player/player_contract.go --config player/config.yml --out player/player.nef --manifest player/config.json
|
||||
|
||||
$ neo-go contract compile -in merchant/merchant_contract.go --config merchant/config.yml --out merchant/merchant.nef --manifest merchant/confi
|
||||
g.json
|
||||
```
|
||||
|
||||
### 2. Assign player contract to the group
|
||||
|
||||
Now we will create a wallet for a group that will contain both contracts. It is possible to skip this step and use wallet `frostfs-aio/morph/node-wallet.json`, but for the sake of purity it is recommended to use a separate wallet.
|
||||
|
||||
To create a wallet, we run the following command. When prompted, enter any name for the account, we will use `l6-game` as group name for this example:
|
||||
|
||||
```sh
|
||||
$ neo-go wallet init -w ../../group-wallet.json -a
|
||||
Enter the name of the account > l6-game
|
||||
Enter new password >
|
||||
Confirm password >
|
||||
```
|
||||
|
||||
Copy account address from the command's output, we will need it in a moment:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"accounts": [
|
||||
{
|
||||
"address": "NgdcCGcR7QveKn9yjQgpemtgtn5zLn33b6", <-- NOTE: take this value
|
||||
...
|
||||
```
|
||||
|
||||
Now we need to assign group to contracts' manifest with the following command (pay attention that sender is address of our wallet with GAS, but --wallet and --address are referring to the group wallet that we've just created):
|
||||
|
||||
```sh
|
||||
$ neo-go contract manifest add-group -n player/player.nef -m player/config.json --sender NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW --wallet ../../group-wallet.json --address NYThT8RYFhkBzJfzMwCe67A63p2WoDev9X
|
||||
```
|
||||
|
||||
Now our contracts are ready to be deployed.
|
||||
|
||||
### 3. Deploy contracts
|
||||
|
||||
Now we can deploy player contract:
|
||||
|
||||
```sh
|
||||
$ $ neo-go contract deploy -r http://localhost:30333 -w ../../wallet.json --in player/player.nef --manifest player/config.json
|
||||
```
|
||||
|
||||
Copy contract hash from the command output and convert it to LE address, for example:
|
||||
|
||||
```sh
|
||||
...
|
||||
Contract: 25b7b493c37fc740bac6603281de01f451847805
|
||||
|
||||
$ neo-go util convert '25b7b493c37fc740bac6603281de01f451847805'
|
||||
BE ScriptHash to Address NPMQFvjSdBWotKA1PrsrkAtiSzyRXPhDF9
|
||||
LE ScriptHash to Address NLQtwNfn4LW3As2r2YfkaRZTpoiTuRfEc5 <-- NOTE: take this value
|
||||
...
|
||||
```
|
||||
|
||||
Now we can deploy merchant contract, it takes hash of player contract as a parameter to its' _deploy method:
|
||||
|
||||
```sh
|
||||
$ neo-go contract deploy -r http://localhost:30333 -w ../../wallet.json --in merchant/merchant.nef --manifest merchant/config.json [ hash160:N
|
||||
LQtwNfn4LW3As2r2YfkaRZTpoiTuRfEc5 ]
|
||||
```
|
||||
|
||||
Copy contract hash from the command output and convert it to LE address, for example:
|
||||
|
||||
```sh
|
||||
...
|
||||
Contract: 443686682d4a3a59408a6b44b766baed894ad679 <-- NOTE: take this value
|
||||
|
||||
$ neo-go util convert '443686682d4a3a59408a6b44b766baed894ad679'
|
||||
BE ScriptHash to Address NS8eTGN8cNabMe6gG9zAZhHyMueuLfM94j
|
||||
LE ScriptHash to Address NX2BfBKZaq2eS28Bn4oDA5uuKFKvB2UpxJ <-- take this value
|
||||
```
|
||||
|
||||
### 4. Create a new player and trade for in-game currency
|
||||
|
||||
To create a new player, invoke `newPlayer` function on the player contract and specify name of the player. In example below we create a player with the name `demo`:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 newPlayer string:demo
|
||||
```
|
||||
|
||||
Try to buy sword with scope None, it should fail:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 buyItem string:demo string:Sword -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:None'
|
||||
```
|
||||
|
||||
Try to do the same with scope CalledByEntry, it should work:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 buyItem string:demo string:Sword -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CalledByEntry'
|
||||
```
|
||||
|
||||
Try to sell item:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 sellItem string:demo string:Sword -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CalledByEntry'
|
||||
```
|
||||
|
||||
Also you can try scopes `CustomContracts` and `CustomGroups`, they should both work too:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 buyItemForGas string:demo int:1 int:23 hash160:NX2BfBKZaq2eS28Bn4oDA5uuKFKvB2UpxJ -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CustomContracts:25b7b493c37fc740bac6603281de01f451847805'
|
||||
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 buyItem string:demo string:Sword -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CustomGroups:029dd9b3639a23ea7ad4356fe7abb4f5a01eaea9f2e5c7138f3e174d21b03f682f'
|
||||
```
|
||||
|
||||
### 5. Trade for gas
|
||||
|
||||
Transfer gas to account of merchant contract (you will need LE address of merchant contract that we've captured during deployment):
|
||||
|
||||
```sh
|
||||
$ neo-go wallet nep17 transfer -r http://localhost:30333 -w ../../frostfs-aio/morph/node-wallet.json --from Nhfg3TbpwogLvDGVvAvqyThbsHgoSU
|
||||
Kwtn --to NX2BfBKZaq2eS28Bn4oDA5uuKFKvB2UpxJ --token GAS --amount 1000
|
||||
```
|
||||
|
||||
Sell Sword to merchant for 20 GAS:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 sellItemForGas string:demo string:Sword int:20 hash160:NX2BfBKZaq2eS28Bn4oDA5uuKFKvB2UpxJ -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CalledByEntry'
|
||||
```
|
||||
|
||||
Buy back sword from merchant for 23 GAS:
|
||||
|
||||
```sh
|
||||
$ neo-go contract invokefunction -r http://localhost:30333 -w ../../wallet.json 25b7b493c37fc740bac6603281de01f451847805 buyItemForGas str
|
||||
ing:demo int:1 int:23 hash160:NX2BfBKZaq2eS28Bn4oDA5uuKFKvB2UpxJ -- 'NP8wjGz3Wvxe4gUAkTbK2McR95Y4LM2jMW:CustomContracts:d2a4cff31913016155e38e474a2c06d08be276cf:25b7b493c37fc740bac6603281de01f451847805'
|
||||
```
|
BIN
l6/docs/blog - thou shalt check their witnesses.pdf
Normal file
BIN
l6/docs/blog - thou shalt check their witnesses.pdf
Normal file
Binary file not shown.
BIN
l6/docs/slides.pdf
Normal file
BIN
l6/docs/slides.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue