Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to run locally and code comments #71

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# sway-farm
# Sway Farm

A simple farming game written in Sway.

## Running Locally

Make sure you have [`fuelup`](https://docs.fuel.network/guides/installation/) installed and are using the `latest` toolchain.

Install a Fuel-compatible wallet extension and copy your wallet address in b256 format (it should start with `0x` instead of `fuel`). In the frontend folder, open the `src/chainConfig.json` file and edit line 7 to use your address. This step will make sure your wallet has test funds on your local network.
Install a Fuel-compatible wallet extension and copy your wallet address in b256 format (it should start with `0x` instead of `fuel`). Open the `chain-snapshot/stateConfig.json` file and edit line 8 to use your address. This step will make sure your wallet has test funds on your local network.

```json
{
"owner": "0xYOUR_ADDRESS_HERE",
"amount": "0x00000000FFFFFFFF",
"asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
```

Run the command below inside the `frontend` folder to start a local node, generate TypeScript types, and deploy the contract locally:
Expand All @@ -25,8 +21,13 @@ npx fuels dev

You should see the message `🎉 Dev completed successfully!`.

Next, run the frontend locally with `npm start`.
Next, open another terminal in the `frontend` folder and run the frontend locally with `npm start`.

```sh
cd frontend
npm start
```

The contract ID will automatically be updated, but the asset ID won't, so you'll have to make sure that is updated everytime the contract redeploys.

Make sure your wallet is also connected to your local network instead of the testnet.
Make sure your wallet is also connected to your local network instead of the testnet. The local network endpoint should be `http://127.0.0.1:4000/v1/graphql`.
271 changes: 271 additions & 0 deletions chain-snapshot/chainConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"chain_name": "local_testnet",
"consensus_parameters": {
"V1": {
"tx_params": {
"V1": {
"max_inputs": 255,
"max_outputs": 255,
"max_witnesses": 255,
"max_gas_per_tx": 100000000,
"max_size": 262144,
"max_bytecode_subsections": 256
}
},
"predicate_params": {
"V1": {
"max_predicate_length": 102400,
"max_predicate_data_length": 102400,
"max_message_data_length": 102400,
"max_gas_per_predicate": 100000000
}
},
"script_params": {
"V1": {
"max_script_length": 102400,
"max_script_data_length": 102400
}
},
"contract_params": {
"V1": {
"contract_max_size": 262144,
"max_storage_slots": 1760
}
},
"fee_params": {
"V1": {
"gas_price_factor": 92,
"gas_per_byte": 63
}
},
"chain_id": 0,
"gas_costs": {
"V1": {
"add": 2,
"addi": 2,
"aloc": 2,
"and": 2,
"andi": 2,
"bal": 86,
"bhei": 2,
"bhsh": 2,
"burn": 25770,
"cb": 2,
"cfei": 2,
"cfsi": 2,
"div": 2,
"divi": 2,
"eck1": 3114,
"ecr1": 42270,
"ed19": 2878,
"eq": 2,
"exp": 2,
"expi": 2,
"flag": 1,
"gm": 2,
"gt": 2,
"gtf": 12,
"ji": 2,
"jmp": 2,
"jne": 2,
"jnei": 2,
"jnzi": 2,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"lb": 2,
"log": 165,
"lt": 2,
"lw": 2,
"mint": 29024,
"mlog": 2,
"mod_op": 2,
"modi": 2,
"move_op": 2,
"movi": 2,
"mroo": 4,
"mul": 2,
"muli": 2,
"mldv": 3,
"noop": 1,
"not": 2,
"or": 2,
"ori": 2,
"poph": 3,
"popl": 3,
"pshh": 4,
"pshl": 4,
"ret": 134,
"rvrt": 153,
"sb": 2,
"sll": 2,
"slli": 2,
"srl": 2,
"srli": 2,
"srw": 209,
"sub": 2,
"subi": 2,
"sw": 2,
"sww": 22501,
"time": 50,
"tr": 33912,
"tro": 24294,
"wdcm": 2,
"wqcm": 3,
"wdop": 3,
"wqop": 3,
"wdml": 3,
"wqml": 4,
"wddv": 5,
"wqdv": 6,
"wdmd": 10,
"wqmd": 17,
"wdam": 9,
"wqam": 11,
"wdmm": 10,
"wqmm": 10,
"xor": 2,
"xori": 2,
"call": {
"LightOperation": {
"base": 18190,
"units_per_gas": 5
}
},
"ccp": {
"LightOperation": {
"base": 48,
"units_per_gas": 22
}
},
"croo": {
"LightOperation": {
"base": 131,
"units_per_gas": 2
}
},
"csiz": {
"LightOperation": {
"base": 45,
"units_per_gas": 237
}
},
"k256": {
"LightOperation": {
"base": 37,
"units_per_gas": 3
}
},
"ldc": {
"LightOperation": {
"base": 39,
"units_per_gas": 68
}
},
"logd": {
"LightOperation": {
"base": 565,
"units_per_gas": 2
}
},
"mcl": {
"LightOperation": {
"base": 3,
"units_per_gas": 564
}
},
"mcli": {
"LightOperation": {
"base": 3,
"units_per_gas": 560
}
},
"mcp": {
"LightOperation": {
"base": 4,
"units_per_gas": 185
}
},
"mcpi": {
"LightOperation": {
"base": 9,
"units_per_gas": 455
}
},
"meq": {
"LightOperation": {
"base": 3,
"units_per_gas": 766
}
},
"retd": {
"LightOperation": {
"base": 485,
"units_per_gas": 3
}
},
"s256": {
"LightOperation": {
"base": 42,
"units_per_gas": 3
}
},
"scwq": {
"HeavyOperation": {
"base": 21672,
"gas_per_unit": 22146
}
},
"smo": {
"LightOperation": {
"base": 44437,
"units_per_gas": 1
}
},
"srwq": {
"HeavyOperation": {
"base": 239,
"gas_per_unit": 234
}
},
"swwq": {
"HeavyOperation": {
"base": 22724,
"gas_per_unit": 21231
}
},
"contract_root": {
"LightOperation": {
"base": 42,
"units_per_gas": 2
}
},
"state_root": {
"HeavyOperation": {
"base": 323,
"gas_per_unit": 169
}
},
"new_storage_per_byte": 63,
"vm_initialization": {
"HeavyOperation": {
"base": 5254820,
"gas_per_unit": 0
}
}
}
},
"base_asset_id": "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07",
"block_gas_limit": 100000000,
"privileged_address": "0000000000000000000000000000000000000000000000000000000000000000"
}
},
"consensus": {
"PoA": {
"signing_key": "0x94ffcc53b892684acefaebc8a3d4a595e528a8cf664eeb3ef36f1020b0809d0d"
}
}
}
8 changes: 8 additions & 0 deletions chain-snapshot/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"chain_config": "chainConfig.json",
"table_encoding": {
"Json": {
"filepath": "stateConfig.json"
}
}
}
51 changes: 51 additions & 0 deletions chain-snapshot/stateConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"coins": [
{
"tx_id": "0x0000000000000000000000000000000000000000000000000000000000000001",
"output_index": 0,
"tx_pointer_block_height": 0,
"tx_pointer_tx_idx": 0,
"owner": "0x488284d46414347c78221d3bad71dfebcff61ab2ae26d71129701d50796f714d",
"amount": 1000000000,
"asset_id": "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
},
{
"tx_id": "0x0000000000000000000000000000000000000000000000000000000000000002",
"output_index": 0,
"tx_pointer_block_height": 0,
"tx_pointer_tx_idx": 0,
"owner": "0x94ffcc53b892684acefaebc8a3d4a595e528a8cf664eeb3ef36f1020b0809d0d",
"amount": 18446744073709551615,
"asset_id": "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
}
],
"messages": [
{
"sender": "0xc43454aa38dd91f88109a4b7aef5efb96ce34e3f24992fe0f81d233ca686f80f",
"recipient": "0x69a2b736b60159b43bb8a4f98c0589f6da5fa3a3d101e8e269c499eb942753ba",
"nonce": "0101010101010101010101010101010101010101010101010101010101010101",
"amount": 18446744073709551615,
"data": "",
"da_height": 0
},
{
"sender": "0x69a2b736b60159b43bb8a4f98c0589f6da5fa3a3d101e8e269c499eb942753ba",
"recipient": "0xc43454aa38dd91f88109a4b7aef5efb96ce34e3f24992fe0f81d233ca686f80f",
"nonce": "0e1ef2963832068b0e1ef2963832068b0e1ef2963832068b0e1ef2963832068b",
"amount": 12704439083013451934,
"data": "",
"da_height": 0
},
{
"sender": "0x22cae5308938e8b4caf217b6464884f6331eff05e81468df8ccd08126effc8d0",
"recipient": "0x8d2af98a4198732a46bf65d87a73427dd7608acaad2414585d8ccdd6f59c437b",
"nonce": "0x381de90750098776c71544527fd253412908dec3d07ce9a7367bd1ba975908a0",
"amount": 18446744073709551615,
"data": "",
"da_height": 0
}
],
"contracts": [],
"block_height": 0,
"da_block_height": 0
}
Empty file.
4 changes: 2 additions & 2 deletions contract/Forc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ dependencies = ["std"]

[[package]]
name = "core"
source = "path+from-root-148AAAB4460F1A9D"
source = "path+from-root-E19CE48B3E858B72"

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.59.0#d9985d8111f94235edba9a08fc71a9513ec2a95c"
source = "git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6"
dependencies = ["core"]
Loading
Loading