Giter Site home page Giter Site logo

dapp-scaffold's Introduction

Solana dApp Scaffold Next

The Solana dApp Scaffold repos are meant to house good starting scaffolds for ecosystem developers to get up and running quickly with a front end client UI that integrates several common features found in dApps with some basic usage examples. Wallet Integration. State management. Components examples. Notifications. Setup recommendations.

Responsive Desktop

Getting Started

This is a Next.js project bootstrapped with create-next-app.

The responsive version for wallets and wallet adapter may not function or work as expected for mobile based on plugin and wallet compatibility. For more code examples and implementations please visit the Solana Cookbook

Installation

npm install
# or
yarn install

Build and Run

Next, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Features

Each Scaffold will contain at least the following features:

Wallet Integration with Auto Connec / Refresh

State Management

Components: One or more components demonstrating state management

Web3 Js: Examples of one or more uses of web3 js including a transaction with a connection provider

Sample navigation and page changing to demonstate state

Clean Simple Styling 

Notifications (optional): Example of using a notification system

A Solana Components Repo will be released in the near future to house a common components library.

Structure

The scaffold project structure may vary based on the front end framework being utilized. The below is an example structure for the Next js Scaffold.

├── public : publically hosted files
├── src : primary code folders and files 
│   ├── components : should house anything considered a resuable UI component
│   ├── contexts` : any context considered reusable and useuful to many compoennts that can be passed down through a component tree
│   ├── hooks` : any functions that let you 'hook' into react state or lifecycle features from function components
│   ├── models` : any data structure that may be reused throughout the project
│   ├── pages` : the pages that host meta data and the intended `View` for the page
│   ├── stores` : stores used in state management
│   ├── styles` : contain any global and reusable styles
│   ├── utils` : any other functionality considered reusable code that can be referenced
│   ├── views` : contains the actual views of the project that include the main content and components within
style, package, configuration, and other project files

Contributing

Anyone is welcome to create an issue to build, discuss or request a new feature or update to the existing code base. Please keep in mind the following when submitting an issue. We consider merging high value features that may be utilized by the majority of scaffold users. If this is not a common feature or fix, consider adding it to the component library or cookbook. Please refer to the project's architecture and style when contributing.

If submitting a feature, please reference the project structure shown above and try to follow the overall architecture and style presented in the existing scaffold.

Committing

To choose a task or make your own, do the following:

  1. Add an issue for the task and assign it to yourself or comment on the issue
  2. Make a draft PR referencing the issue.

The general flow for making a contribution:

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

You can find tasks on the project board or create an issue and assign it to yourself.

Learn More Next Js

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

dapp-scaffold's People

Contributors

alexmgn avatar arrowana avatar bartosz-lipinski avatar dependabot[bot] avatar donnysolana avatar ebramanti avatar gabedottl avatar halaprix avatar haresmahmood avatar jacobcreech avatar johnnieskywalker avatar johnrees avatar joncinque avatar josip-volarevic avatar kevinrodriguez-io avatar macalinao avatar max-block avatar mordonez-me avatar mwrites avatar rmshea avatar ronnyhaase avatar steveluscher avatar tidelaw avatar tina1998612 avatar ytw7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dapp-scaffold's Issues

how do you debug on vscode with CodeLLDB , cargo test-bpf failing

Hi im trying to use Debug on VSCode on Mac M1

  • rustc 1.55.0
  • rustup 1.24.3
  • cargo 1.55.0
  • solana 1.7.12

I need to find out what is the executable file generated ,
there is no .dmg or .app so i dont think there is a executable generated

i did run cargo build and cargo build-bpf (prior version of solana 1.7.11 is failing installed in brew)
it generated *.so file needed to be deploy on the test network.
I manage to upload it

this is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "(Mac M1) Launch",
            "host": "arm64",
            // update this to point to the executable
            "program": "${workspaceFolder}/program/target/debug/${DONT KNOW WHAT EXECUTABEL TO PUT HERE}",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

Here is the File Structure in my Mac M1:

Screen Shot 2021-09-19 at 10 33 48 PM

I also faced issue on running

cargo test-bpf

which i think also other people here is facing...

Template File Does Not Exist

Running the command: npm run localnet:up gives this error:


> [email protected] localnet:up /Users/jim/Git-Projects/JJ-Solana-Dapp
> solana-test-validator --bpf-program BpfProgram1111111111111111111111111111111111 program/target/deploy/bpf_program_template.so --reset

Error: program file does not exist: program/target/deploy/bpf_program_template.so
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] localnet:up: `solana-test-validator --bpf-program BpfProgram1111111111111111111111111111111111 program/target/deploy/bpf_program_template.so --reset`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] localnet:up script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jim/.npm/_logs/2021-12-05T19_42_12_820Z-debug.log

WebSocket connection Issue

websocket.browser.js:47 WebSocket connection to 'wss://testnet.solana.com/' failed:
WebSocketBrowserImpl @ websocket.browser.js:47
_default @ websocket.browser.js:121
_connect @ client.js:387
(anonymous) @ client.js:453
index.js:1 ws error: undefined

Please check

README new-issue link error

1. [Add an issue](https://github.com/solana-dev-adv/solana-dapp-next/issues/new) for the task and assign it to yourself or comment on the issue

link to another repository

Unhandled Rejection (error): Not a valid Mint

throw new Error("Not a valid Mint");

Reproduction:
git clone https://github.com/solana-labs/dapp-scaffold.git
yarn
yarn start

Run on an incognito window or a browser that hadn't cached anything before.

If an invalid token is provided by a TokenProvider, it crashes the whole app.

A solution is wrapping

const account = deserialize(new PublicKey(address), obj);

In a try-catch block.

Is this project alive ?

Simply following README fails.

No commit for 6months, plenty of bugs PR left unattended ...

hence the question

cargo test-bpf Stalls on librocksdb-sys v6.17.3

Hello,

Cargo test-bpf hangs up on 653/665 at time of initial compilation for librocksdb-sys. I believe I installed all of the needed dependencies, but it just sits there to no avail. We're running Ubuntu 20.04. Does anyone have any insight as to how to complete or override if possible. Would like to see the test-bpf complete without errors.

Thanks again,

Frank

Eslint config

Let us config eslint to match coding style to contribute!
Please add public code style in .eslintrc.json file
And please add this line in scripts of package.json file as a command
"lint:fix": "next lint -- --fix"
by using this command, we can match code style automatically when commit or create PR after changing the file.

Thanks!

Error on yarn start

Hi, This is the error i get after simple clone and run.

Failed to compile.

./node_modules/@solana/wallet-adapter-ant-design/lib/esm/WalletMultiButton.mjs
Can't import the named export 'Button' from non EcmaScript module (only default export is available)

Also get the following error on browser.
image

Cant change background

n00b question, but where can I change the background? I used to be able to change it in the App.less by adding 'background: etc' to body {} but it still stays black when I do. I am sure it is an easy change but was getting stuck.

Change Mainnet

I want to change solana devnet to solana mainnet. Where can i fix this and how?

Phantom icon

Hi,

Why don't I have the Phantom icon ? (got all the other ones)

image

Thanks

Default token mints subscriptions, killer for public rpc and private pools

Every single token mint in spl-token-registry is added to the cache

const [tokenMap, setTokenMap] = useState<Map<string, TokenInfo>>(new Map());
useEffect(() => {
cache.clear();
// fetch token files
(async () => {
const res = await new TokenListProvider().resolve();
const list = res
.filterByChainId(chain.chainID)
.excludeByTag("nft")
.getList();
const knownMints = list.reduce((map, item) => {
map.set(item.address, item);
return map;
}, new Map<string, TokenInfo>());
const accounts = await getMultipleAccounts(connection, [...knownMints.keys()], 'single');
accounts.keys.forEach((key, index) => {
const account = accounts.array[index];
if(!account) {
return;
}
cache.add(new PublicKey(key), account, MintParser);
})
setTokenMap(knownMints);
setTokens(list);
})();
}, [connection, chain]);

Adding to the cache has a side effect, creating a subscription to the added account:

useEffect(() => {
const subs: number[] = [];
cache.emitter.onCache((args) => {
if (args.isNew) {
let id = args.id;
let deserialize = args.parser;
connection.onAccountChange(new PublicKey(id), (info) => {
cache.add(id, info, deserialize);
});
}
});

This problem is invisible on devnet as the token list is small, but once plugged to mainnet this is a node/rpcpool killer as the code will open a great number of account subscriptions through onAccountChange

In most cases an up to date token mint is not required, only in rare cases it is useful (LP token supply...).

This should be reworked so the dapp-scaffold boilerplate is not a trap.

Here is a screenshot of the swarm of accountSubscribe in the websocket, it can't even fit on the screen
Screenshot from 2021-07-22 18-39-12

Some of which are essential tokens to be monitored
Screenshot from 2021-07-22 17-54-47

Send transaction doesn't seem to connect to devnet on my wallet

Hi,

Getting the following error: failed to send transaction: Transaction simulation failed: Transaction leaves an account with a lower balance than rent-exempt minimum

I believe my wallet is working properly and is set to Devnet but it doesn't seem like it is being recognized during the send transaction process. I'm able to airdrop money to it though for some reason. Other folks have tested my code and it works fine for them with Phantom. I'm using Solflare.

Any help is appreciated.

connection.tsx - wallet.signTransaction(...) function does not exist.

dapp-scaffold/src/contexts/connection.tsx

At line 257 in connection.tsx there is a function call to wallet.signTransaction(...)

transaction = await wallet.signTransaction(transaction);

VSCode gives me the following tool tip Property 'signTransaction' does not exist on type 'WalletAdapter'. Did you mean 'sendTransaction'?

I go to the definition of wallet which is of type WalletAdapter which is imported from @solana/wallet-adapter-base

The definition there extends WalletAdapaterProps & EventEmitter<WalletAdapterEvents>

WalletAdapterProps is an interface and is missing the field signTransaction which is being called at the top level await wallet.signTransaction()

I'm new to solana, rust, and react and was wondering if I can get some help here. I was thinking that this was perhaps deprecated but I couldn't find any information.

This is the only issue I'm having after a clean git clone followed by a yarn install.

Operation on an invalid type

After doing yarn start, in the react app, I'm getting the following error:

Failed to compile
./src/App.less (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-7-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-7-3!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-7-4!./src/App.less)

// ================================================================
.table-size(~'middle', @table-padding-vertical-md, @table-padding-horizontal-md, @table-font-size-md);
^
Operation on an invalid type
      Error in /Users/prikshetsharma/Desktop/dapp-scaffold/node_modules/antd/lib/table/style/size.less (line 53, column 0)

How to fix this?

Multiple Vulnerabilities

Dependabot did some scans and revealed multiple active exploits in the dapp-scaffold. Is there any plans to patch these RCE exploits? If this is not taken care of, SOL will die hard in the coming year.

Build command errors with librocksdb-sys v6.11.4

The server runs successfully for me and my machine is properly configured - I can for example build and run examples from here.

Here I get errors on cargo test (build is successful).

$ cargo test
   Compiling librocksdb-sys v6.11.4
   Compiling bpf-program-template v0.1.0 (/home/tenoke/Documents/sol/dapp-scaffold/program)
warning: Error finalizing incremental compilation session directory `/home/tenoke/Documents/sol/dapp-scaffold/program/target/debug/incremental/bpf_program_template-q18mnzxl1jtp/s-fwb7befgcz-vmsrxf-working`: Permission denied (os error 13)

warning: 1 warning emitted

error: failed to run custom build command for `librocksdb-sys v6.11.4`

Caused by:
  process didn't exit successfully: `/home/tenoke/Documents/sol/dapp-scaffold/program/target/debug/build/librocksdb-sys-4417be20bf0e8189/build-script-build` (exit code: 101)
  --- stderr
  rocksdb/include/rocksdb/c.h:65:10: fatal error: 'stdarg.h' file not found
  rocksdb/include/rocksdb/c.h:65:10: fatal error: 'stdarg.h' file not found, err: true
  thread 'main' panicked at 'unable to generate rocksdb bindings: ()', /home/tenoke/.cargo/registry/src/github.com-1ecc6299db9ec823/librocksdb-sys-6.11.4/build.rs:44:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Basic example of storing a data on a hash table / key value pair

Hi there - I've been trying to find a basic example of Solana + React to do the basics of a CRUD web app. From React through to Rust contract:

  • Register a new user e.g. registerUser(string userName) stores userName against the users public address in a hashset/hashtable/keyvaluepair in Rust, returns a new unique userId e.g. int64
  • Lookup a "record" (e.g.user/customer/order) via lookupCustomer(int customerId), returns plain javascript object e.g. { "firstName": "Ash", "lastName": "Rudland" }, assuming this could be a hashtable/hashset/keyvaluepair too.

I gave up after a few weeks, would really help so many of us app developers getting into Solana and just trying to find a simple example of what we would like to build.

Thanks!

How to use with Anchor

Does anyone have tips or an example on how to use this scaffold and all of the wallet plumbing that goes with it, to load an IDL from a program built and deployed with Anchor and interact with it? For the life of me I cannot find a working example.

Garbage Scaffolding

The recommendation is to just clone this repo? WTF??? 😂

A proper scaffolding should be able to create the project folder within an existing repo. duh...

Project uses package-lock.json but README uses yarn

The project uses package-lock.json. So I think we should be using npm instead of yarn in the README quickstart code.

The yarn installer even gives us a handy warning.

warning package-lock.json found. Your project contains lock files generated by tools other than Yarn.
It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files.
To clear this warning, remove package-lock.json.

Error: error - ./node_modules/is-nan/index.js:4:0

error - ./node_modules/is-nan/index.js:4:0
Module not found: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: /Users/davirain/rust/chinese-chess/node_modules/define-properties/package.json (directory description file): SyntaxError: Unexpected end of JSON input

Import trace for requested module:
./node_modules/assert/build/internal/util/comparisons.js
./node_modules/assert/build/assert.js
./node_modules/ethereumjs-util/dist.browser/account.js
./node_modules/ethereumjs-util/dist.browser/index.js
./node_modules/@toruslabs/base-controllers/dist/baseControllers.esm.js
./node_modules/@toruslabs/solana-embed/dist/solanaEmbed.esm.js
./node_modules/@solana/wallet-adapter-torus/lib/esm/adapter.js
./node_modules/@solana/wallet-adapter-torus/lib/esm/index.js
./node_modules/@solana/wallet-adapter-wallets/lib/esm/index.js
./src/contexts/ContextProvider.tsx
./src/pages/_app.tsx

https://nextjs.org/docs/messages/module-not-found

Error on startup: unhandled rejection

Error seen by me and another dev on discord, it happens when the app first starts and is loaded by the browser

Error is Unhandled Rejection: failed to get info about account Invalid Param: Wrong Size

I tracked it down to the getMultipleAccounts call in connection.tsx
Some of the known mint addresses had a trailing space in the address.

The below patch fixed it for me , but not sure if there is a better way to patch upstream of this to fix the addresses

diff --git a/src/contexts/connection.tsx b/src/contexts/connection.tsx
index 5d864e9..215eea5 100644
--- a/src/contexts/connection.tsx
+++ b/src/contexts/connection.tsx
@@ -105,7 +105,7 @@ export function ConnectionProvider({ children = undefined as any }) {
         .excludeByTag("nft")
         .getList();
       const knownMints = list.reduce((map, item) => {
-        map.set(item.address, item);
+        map.set(item.address.trim(), item);
         return map;
       }, new Map<string, TokenInfo>());
 

Transaction creation failed.

Just trying the out of the box transaction an error:

Phantom - RPC Error: Transaction creation failed. {code: -32003, message: 'Transaction creation failed.'}

Action State and Buttons

Currently actions triggered by buttons are stateless. When you click to send a transaction the user is not aware if anything happened until the actions responds from the call being made. There could be a few approaches to solving this issue.

Solution Ideas:

In the case of a button,

  • Manage action states in such a way that when clicked the button state is disabled until a response is received and then re enabled.
  • Additionally produce an optional busy or spinner/loading modal that shows the user the transaction is processing and optionally automatically closes when done.

yarn test failing due to superstruct dependency

When I pull a fresh copy of this repo, I get the following error from Jest:

 FAIL  src/App.test.tsx
  ● Test suite failed to run

    TypeError: superstruct.instance is not a function

      1 | import type { PublicKey } from "@solana/web3.js";
      2 | 
    > 3 | import Wallet from "@project-serum/sol-wallet-adapter";
        | ^
      4 | import { Transaction } from "@solana/web3.js";
      5 | import { Button, Modal } from "antd";
      6 | import EventEmitter from "eventemitter3";

      at Object.<anonymous> (node_modules/@solana/web3.js/src/connection.ts:45:3)
      at Object.<anonymous> (node_modules/@project-serum/sol-wallet-adapter/dist/index.js:4:15)
      at Object.<anonymous> (src/contexts/wallet.tsx:3:1)
      at Object.<anonymous> (src/routes.tsx:3:1)
      at Object.<anonymous> (src/App.tsx:3:1)
      at Object.<anonymous> (src/App.test.tsx:3:1)
      at processTicksAndRejections (node:internal/process/task_queues:93:5)

I think it has something to do with the @solana/web3.js dependency being different in the @project-serum sub-dependencies, but not quite sure.

"Expired transaction" - ERROR

We are getting "expired transaction error" in phatom while trying to send any transaction in the devnet or testnet. Signing a message works fine. It pop ups the error without any possibility to click the approve button or anything. This doesn't happen in the mainnet weirdly, just the other 2 nets.

cargo test-bpf fails on M1 Mac

I've been trying to set this up per the instructions. Once I run

cargo test-bpf

I get the foll0wing error:
failed to run custom build command for ring v0.16.12`

When I try to update to update it per the seggestion of dev of ring briansmith/ring#1163 by adding

ring = "0.16.19"

to the Cargo.tml, I get the following:

Failed to obtain package metadata: Error during execution of `cargo metadata`:     Updating crates.io index
error: failed to select a version for `cc`.
    ... required by package `ring v0.16.19`
    ... which is depended on by `bpf-program-template v0.1.0 (/Users/erick/Documents/Code/dapp-scaffold/program)`
versions that meet the requirements `^1.0.62` are: 1.0.67, 1.0.66, 1.0.65, 1.0.64, 1.0.63, 1.0.62

all possible versions conflict with previously selected packages.

  previously selected package `cc v1.0.45`
    ... which is depended on by `solana-crate-features v1.6.7`
    ... which is depended on by `solana-sdk v1.6.7`
    ... which is depended on by `bpf-program-template v0.1.0 (/Users/erick/Documents/Code/dapp-scaffold/program)`

failed to select a version for `cc` which could resolve this conflict

How do I move past this? I tied adding:
cc = "^1.0.62"

to the Cargo.toml, and it still has issues:


Failed to obtain package metadata: Error during execution of `cargo metadata`:     Updating crates.io index
error: failed to select a version for `cc`.
    ... required by package `bpf-program-template v0.1.0 (/Users/erick/Documents/Code/dapp-scaffold/program)`
versions that meet the requirements `^1.0.62` are: 1.0.67, 1.0.66, 1.0.65, 1.0.64, 1.0.63, 1.0.62

all possible versions conflict with previously selected packages.

  previously selected package `cc v1.0.45`
    ... which is depended on by `solana-crate-features v1.6.7`
    ... which is depended on by `solana-sdk v1.6.7`
    ... which is depended on by `bpf-program-template v0.1.0 (/Users/erick/Documents/Code/dapp-scaffold/program)`

failed to select a version for `cc` which could resolve this conflict

What can be done to resolve this?

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.