This is an opiniated web3 frontend starter template from TreasureDAO.
- Remix
- Tailwind CSS
- GraphQL Codegen
- wagmi
- react-hot-toast
- Deployment on fly.io
npm run dev
Open up localhost:3000 and you should be ready to go!
If you are fetching data from an external GraphQL endpoint, first add your endpoint in .env
.
Write your query inside app.queries.ts
. Theres an example in there. When you're done, run npm run codegen
. Your autogenerated code will appear under the same file, /graphql
Then create a file called api.server.ts
under utils. Naming it with a server
prefix will tell Remix to not bundle that file in client JavaScript.
Something like this:
import { GraphQLClient } from "graphql-request";
import { getSdk as getExchangeSdk } from "~/graphql/exchange.generated";
// Passing URL here, since you'd want to have different endpoints depending on production or not
export const exchangeSdk = (url: string) =>
getExchangeSdk(new GraphQLClient(url, { fetch }));
Now you can use this in your loaders, where it will fetch from that endpoint and server side render your app.
ex.
import { exchangeSdk } from "~/utils.api.server";
export const loader: LoaderFunction = async () => {
const sdk = exchangeSdk(url);
return json<LoaderData>({
data: await sdk.hello(),
});
};
// then use it client like this:
export default function Index() {
const data = useLoaderData<typeof loader>();
return <div>{data.hello}</div>;
}
-
run
fly launch
and configure the repo for fly.io deployement -
npm run deploy