useink
is a React hooks library for Substrate and Wasm contracts on Substrate
- Wrap your application in the
UseInkProvider
. The fielddappName
will show up in browser wallet extensions when a user is prompted to authorize a connection.
import { UseInkProvider } from 'useink';
root.render(
<UseInkProvider
config={{
dappName: 'My Dapp',
providerUrl: 'wss://rococo-contracts-rpc.polkadot.io',
}}
>
{children}
</UseInkProvider>,
);
- Connecting a wallet -
useink
provides a hook calleduseExtension
that uses [@polkadot/extension-dapp]. Once a wallet is connected the account is stored in local storage so that if the page refreshes the Dapp will auto connect. You can turn this feature off by passing in{ extensions: { skipAutoConnect: true } }
to the config inUseInkProvider
.
import { useExtension } from 'useink';
export const Connector = () => {
const { account, connect, disconnect } = useExtension();
if (!account) {
return <button onClick={connect}>Connect</button>;
}
return {
<>
<button onClick={disconnect}>Disconnect</button>;
{// show my dapp view...}
</>
}
};
There are more features inside of useExtension
and many more hooks in
useink
.
You can find examples and patterns here:
Everyone interacting in this repo is expected to follow the code of conduct.
Contributions are welcome and appreciated! Check out the contributing guide before you dive in.
useInk! is Apache licensed.