{"id":24995423,"url":"https://github.com/compolabs/fuel-indexer-tutorial","last_synced_at":"2025-04-12T04:11:14.900Z","repository":{"id":184078717,"uuid":"671176100","full_name":"compolabs/fuel-indexer-tutorial","owner":"compolabs","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-05T22:47:42.000Z","size":54,"stargazers_count":74,"open_issues_count":0,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T23:41:47.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/compolabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-26T18:01:33.000Z","updated_at":"2025-01-10T12:41:17.000Z","dependencies_parsed_at":"2025-02-04T15:38:43.745Z","dependency_job_id":"647caa47-9560-4c06-b342-3b5f297f6a0a","html_url":"https://github.com/compolabs/fuel-indexer-tutorial","commit_stats":null,"previous_names":["compolabs/fuel-indexer-tutorial"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Ffuel-indexer-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Ffuel-indexer-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Ffuel-indexer-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Ffuel-indexer-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compolabs","download_url":"https://codeload.github.com/compolabs/fuel-indexer-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514221,"owners_count":21116903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T15:37:54.789Z","updated_at":"2025-04-12T04:11:14.873Z","avatar_url":"https://github.com/compolabs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to Index Data on the Fuel Network using Fuel Indexer \n\nRepository: https://github.com/compolabs/fuel-indexer-tutorial\n\nℹ️ If you have any questions you can ask them in our telegram chat for developers: \nhttps://t.me/compolabs_devs.\n\nWelcome to an advanced tutorial by Composability Labs on how to index events on the blockchain fuel.network using the fuel indexer.\n\nYou can find the source code for this tutorial here: [fuel-indexer-tutorial](https://github.com/compolabs/fuel-indexer-tutorial/tree/master)\n\n⚠️ Before going through this tutorial, make sure you have the required dependencies installed\n\n## Counter Contract Test Project\n\n1. Create a test counter project:\n```bash\nforc new counter    \ncd counter\ncargo generate --init fuellabs/sway templates/sway-test-rs --name counter\n```\n\n2. Add your beta-3 account's private key with some ETH balance (to pay fees) into a `.env` file at the root of the `counter` folder.\n\nExample: [.env.example](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter/.env.example)\n\n3. Change the Rust SDK version in the `Cargo.toml` to 0.41.1 to allow usage of beta-3. Your `Cargo.toml` should look like this: [Cargo.toml](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter/Cargo.toml)\n\n4. The code for the contract `src/main.sw` can be found here: [main.sw](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter/src/main.sw)\n\n5. The test code can be found in `tests/harness.rs`: [harness.rs](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter/tests/harness.rs). This test contains both local node and testnet tests, with the latter used to generate events.\n\n6. Build the contract using `forc build`.\n\n⚠️ Before building of contract, please ensure that you are using the beta-3 version of the toolchain. You can switch your toolchain to beta-3 using the following commands:\n\n```bash\nfuelup update\nfuelup toolchain install beta-3   \nfuelup default beta-3\n```\n\nto come back to `latest` you can type `fuelup default latest`\n\nDone! The code is ready. Now let's deploy our contracts. Alternatively, you can use the already deployed contract address on beta-3:\n\n- 0x..   Address: `0xd968d8c91c8f7a4b09e86fb5080a1cb9bcd8b016f2764751e1c900d2be20b0cc`\n- fuel.. Address: `fuel1m95d3jgu3aaykz0gd76sszsuhx7d3vqk7fmyw50peyqd903qkrxq67czu2`\n\n---\n## Indexer Instance Test Project\n\n1. Create a new indexer instance near the `counter` folder:\n```bash\nforc index new counter_indexer --namespace composabilitylabs   \ncd counter_indexer\n```\n\n2. First, copy the ABI file from `counter/out/debug/counter-abi.json` into `counter_indexer/`.\n\n3. Edit the `counter_indexer/schema/counter_indexer.schema.graphql` file to match the following schema: [counter_indexer.schema.graphql](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter_indexer/schema/counter_indexer.schema.graphql)\n\n4. Create a `counter_indexer/src/lib.rs` file like this: [lib.rs](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter_indexer/src/lib.rs)\n\n5. Create the `counter_indexer/counter_indexer.manifest.yaml` manifest as shown here: [counter_indexer.manifest.yaml](https://github.com/compolabs/fuel-indexer-tutorial/blob/master/counter_indexer/counter_indexer.manifest.yaml)\n\n6. If you want to avoid waiting for a long sync, you can change the `start_block` at the end from the fuel explorer.\n\n7. Run the database in a Docker container:\n```bash\ndocker run -d -p 5432:5432 --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres\n```\n\n8. Run the fuel-indexer:\n```bash\nfuel-indexer run --run-migrations --fuel-node-host beta-3.fuel.network --fuel-node-port 80 --postgres-host 127.0.0.1 --postgres-port 5432 --postgres-password mysecretpassword --postgres-user postgres\n```\n\n9. Deploy the indexer:\n```bash\nforc index deploy\n```\n\nDone! Now you will see some logs like `INFO fuel_indexer::ffi: 55: Increment 6 -\u003e 7` in your fuel-indexer shell.\n\nTo redeploy the indexer code, you can use the following commands:\n```bash\nforc index remove\nforc index deploy\n```\n\nAdditionally, the GraphQL playground is available at the URL: [http://localhost:29987/api/playground/composabilitylabs/counter_indexer](http://localhost:29987/api/playground/composabilitylabs/counter_indexer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Ffuel-indexer-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompolabs%2Ffuel-indexer-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Ffuel-indexer-tutorial/lists"}