Giter Site home page Giter Site logo

brech1 / sway-frontend Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 73 KB

Next.js implementation of a frontend for a sway contract.

Home Page: https://sway-ui.vercel.app/

License: MIT License

TypeScript 95.56% JavaScript 4.05% CSS 0.40%
nextjs rust typescript fuel sway

sway-frontend's Introduction

Sway Frontend Template

469dfcb6-d1dd-4d23-9fe0-6a0c6b20caac

Take a look at the template working here.

This project aims to:

  • Make it easier for people to try sway contracts.
  • Give examples to build on fuel.

It features:

  • Wallet generation script
  • Contract build and deploy scripts
  • Contract types generation scripts

The main structure is that of a regular next.js project. But there are two main folders where most of the work will be done:

  • app : Here resides the configuration for our frontend app and the main components of our site.
  • contract : This folder will contain our sway contract.

The contract being used as example is a simplified version of a vault contract. The user can make deposits and then claim them if it's the owner of that deposit.

The frontend stack is:

  • Typescript
  • Next.js
  • Tailwind

Getting Started

1. Make sure to have rust and cargo installed. Also fuelup:

$curl --proto '=https' --tlsv1.2 -sSf \
https://fuellabs.github.io/fuelup/fuelup-init.sh | sh

2. Create the contract

You can skip this step if you want to use the example contract or if already have your contract built, just copy your folder and change the name to contract and be aware that you should also modify the contract script on the package.json file to the actual name of the binary.

$forc new contract

Using the template

3. Compile your contract

$yarn build:contract

This script will compile your contract and generate the binaries.

4. Set up your .env file

Before deploying the contract you should set up your wallet address and private key. You can copy the .env.orig file and insert your keys there if you already have a wallet, or you can generate one using the next script:

$yarn gen:wallet

Now you just have to $touch .env and copy the output of this command there.

I'm guessing you'll need some funds. You can ask some eth at the faucet

5. Deploy your contract

$yarn deploy:contract

Use this script to deploy your contract to the fuel network. Once it's deployed correctly make sure to copy the address in the ./app/config.ts file.

6. Generate types

$yarn gen:types

Once you have the binaries of your contract you can generate the types, these will let you use all the methods from your contract in an easy way from your ui application.

Frontend App

7. Test locally

To test your application you have two paths:

$yarn dev

or

$yarn build
$yarn start

The first option is the most convenient way to work with next.js.

8. Deploy your ui

Once you have everything running, you can deploy your application. Be aware that your keys will be public if you use the template as is!

$yarn export

This will generate an out directory that you can easily upload to any hosting service. I recommend uploading to vercel using the Vercel CLI.

sway-frontend's People

Contributors

brech1 avatar

Stargazers

Murat Artan avatar Orpheus Lummis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.