Skip to content

Commit

Permalink
setup for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Apr 11, 2024
1 parent dda7af1 commit b1bffc6
Show file tree
Hide file tree
Showing 13 changed files with 1,158 additions and 800 deletions.
44 changes: 14 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,27 @@ A simple farming game written in Sway.

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

Install the Fuel Wallet extension and copy your wallet address. In the frontend folder, open the `src/App.tsx` file and add the following lines using your Fuel wallet address:

```javascript
const myWallet = new WalletLocked("fuel123....");
console.log("WALLET:", myWallet.address.toB256());
```

Run the frontend locally with `npm start`, and check your console to see your Fuel wallet address in B256 format. Copy this address and update the `owner` field as shown below in the `chainConfig.json` file so that your wallet will have test funds.
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.

```json
"initial_state": {
"coins": [
{
"owner": "0x_YOUR_FUEL_WALLET_ADDRESS",
"amount": "0x00000000FFFFFFFF",
"asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
]
},
{
"owner": "0xYOUR_ADDRESS_HERE",
"amount": "0x00000000FFFFFFFF",
"asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
```

Run the command below in the main project folder to start a local node.
Run the command below inside the `frontend` folder to start a local node, generate TypeScript types, and deploy the contract locally:

```shell
fuel-core run --db-type in-memory --chain ./chainConfig.json
```sh
cd frontend
npx fuels dev
```

Next, in the `contract` folder, run the command below to deploy the contract to your local node.
You should see the message `🎉 Dev completed successfully!`.

```shell
forc deploy --unsigned
```

In your wallet, add a network with `http://127.0.0.1:4000/graphql` and switch to that network.
Next, run the frontend locally with `npm start`.

The contract ID should match the `CONTRACT_ID` in `frontend/src/constants.ts`. If you update the contract and the contract ID changes, you must update it here and run the command below in the `frontend` folder to generate new types.
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.

```shell
npx fuels typegen -i ../contract/out/debug/*-abi.json -o ./src/contracts
```
Make sure your wallet is also connected to your local network instead of the testnet.
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-B672DC9E3D340CD2"
source = "path+from-root-566CA1D5F8BEAFBF"

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.49.2#a70c746d27b3300beef896ccd1dcce1299836192"
source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728"
dependencies = ["core"]
3 changes: 2 additions & 1 deletion frontend/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.html
src/sway-api
**/src/sway-api/**
**/src/sway-api/**/**
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.env.development.local
.env.test.local
.env.production.local
.fuels

npm-debug.log*
yarn-debug.log*
Expand Down
Loading

0 comments on commit b1bffc6

Please sign in to comment.