Skip to content

Commit 36198da

Browse files
authored
add fuel example (#10)
* initialize fuel example * update gitignore * add get_price and update_price_feeds * update * refactor * update deps version * fix * address comments
1 parent cfd9c6d commit 36198da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+10132
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NEXT_PUBLIC_HAS_CONTRACT=true
2+
NEXT_PUBLIC_HAS_PREDICATE=true
3+
NEXT_PUBLIC_HAS_SCRIPT=true
4+
NEXT_PUBLIC_DAPP_ENVIRONMENT=testnet
5+
NEXT_PUBLIC_TESTNET_CONTRACT_ID=0x3e2f83f9bb6dd9bafc3e58bf40f091f3cc1304bd025a2fc70f0e6b2632a46799
6+
NEXT_PUBLIC_PYTH_TESTNET_CONTRACT_ID=0x1ab91bc1402a187055d3e827017ace566a103ce2a4126517da5d656d6a436aea
7+
NEXT_PUBLIC_HERMES_BTC_URL="https://hermes.pyth.network/v2/updates/price/latest?ids[]="
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/sway-api
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"ignoreDuringBuilds": true
4+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# dependencies
2+
/node_modules
3+
/.pnp
4+
.pnp.js
5+
.yarn/install-state.gz
6+
7+
# testing
8+
/coverage
9+
10+
# next.js
11+
/.next/
12+
/out/
13+
14+
# production
15+
/build
16+
17+
# misc
18+
.DS_Store
19+
*.pem
20+
21+
# debug
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# local env files
27+
.env*.local
28+
29+
# vercel
30+
.vercel
31+
32+
# typescript
33+
*.tsbuildinfo
34+
next-env.d.ts
35+
36+
.fuels
37+
38+
src/sway-api/contracts
39+
src/sway-api/predicates
40+
src/sway-api/scripts
41+
src/sway-api/index.ts
42+
43+
sway-programs/**/out
44+
.turbo
45+
46+
# MacOS
47+
.DS_Store
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Fetch and Update BTC Price Example
2+
3+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-fuels`](https://github.com/FuelLabs/fuels-ts/tree/master/packages/create-fuels).
4+
5+
## Getting Started
6+
7+
1. Copy .env.example to .env.local
8+
9+
```bash
10+
cp .env.example .env.local
11+
```
12+
13+
2. Start the Fuel development server. This server will start a local Fuel node and provide hot-reloading for your smart contracts.
14+
15+
```bash
16+
npm run fuels:dev
17+
```
18+
19+
3. Start the Next.js development server.
20+
21+
```bash
22+
npm run dev
23+
```
24+
25+
## Features
26+
27+
- Connects to Fuel wallet
28+
- Fetches BTC/USD price from Pyth Network
29+
- Updates price on-chain using Pyth's price feed
30+
- Displays current price
31+
32+
## Smart Contract
33+
34+
The main contract (`UpdatePrice`) interacts with the Pyth contract to:
35+
36+
- Get the valid time period for price updates
37+
- Fetch price data
38+
- Update price feeds
39+
40+
You can find the contract code [here](sway-programs/contract/src/main.sw).
41+
42+
## Deploying to Testnet
43+
44+
To learn how to deploy your Fuel dApp to the testnet, you can follow our [Deploying to Testnet](https://docs.fuel.network/docs/fuels-ts/creating-a-fuel-dapp/deploying-a-dapp-to-testnet/) guide.
45+
46+
## Learn More
47+
48+
- [Fuel TS SDK docs](https://docs.fuel.network/docs/fuels-ts/)
49+
- [Fuel Docs Portal](https://docs.fuel.network/)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createConfig } from 'fuels';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config({
5+
path: ['.env.local', '.env'],
6+
});
7+
8+
export default createConfig({
9+
contracts: ['./sway-programs/contract'],
10+
output: './src/sway-api',
11+
providerUrl: 'https://testnet.fuel.network/v1/graphql',
12+
privateKey: process.env.PRIVATE_KEY,
13+
forcBuildFlags: ['--release'],
14+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
};
5+
6+
module.exports = nextConfig;

0 commit comments

Comments
 (0)