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

docs: create simple getting started #981

Merged
merged 5 commits into from
May 7, 2023
Merged
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
2 changes: 2 additions & 0 deletions .changeset/perfect-suits-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 4 additions & 0 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default defineConfig({
text: 'Introduction',
link: '/',
items: [
{
text: 'Getting Started',
link: '/getting-started',
},
{
text: 'Glossary',
link: '/glossary',
Expand Down
63 changes: 63 additions & 0 deletions apps/docs/src/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Getting Started with Fuels-ts

This guide will walk you through the process of setting up and using the Fuels-ts library in your front-end project.

## Installing the Fuels-ts Library

To begin, you need to add the `fuels` dependency to your project. You can do this using the following command:

::: code-group
arboleya marked this conversation as resolved.
Show resolved Hide resolved

```sh [npm]
npm install fuels --save
```

```sh [yarn]
yarn add fuels
```

```sh [pnpm]
pnpm add fuels
```

:::

## Creating a React Component to Connect to the Blockchain

With the Fuels dependency set up, you can now create a React component that will connect to the Fuel provider and retrieve the base asset balance for a given wallet address. Here's an example of how to do this:

<!-- TODO: Create properly code snippet on new package: `app/react-app` after https://github.com/FuelLabs/fuels-ts/pull/827 got merged -->

```tsx
import { BN, Provider, Wallet } from "fuels";
import { useEffect, useState } from "react";

function App() {
const [balance, setBalance] = useState(0);

const provider = new Provider("https://beta-3.fuel.network/graphql");
const myWallet = Wallet.fromAddress("0x...", provider);

useEffect(() => {
myWallet.getBalances().then((data) => {
setBalance(new BN(data[0].amount).toNumber());
});
}, []);

return <div>My Balance: {balance}</div>;
}

export default App;
```

## Further Resources and Next Steps

For a more in-depth, step-by-step guide on working with the Fuels ecosystem, check out the [Developer Quickstart guide](https://fuelbook.fuel.network/master/quickstart/developer-quickstart.html). This guide covers:

1. Installing all tools needed to develop on the Fuels ecosystem.

2. Writing your first Sway Project.

3. Deploying your contract.

4. Building a simple front-end dApp to interact with your deployed contract.