Integration instructions
Last updated
Last updated
Integrates your DApp with the Cardano Wallet
Metamask snap. This means that in order to log into your DApp, it is enough for the user to have Metamask installed, removing the need for having a Cardano-specific wallet set up.
Example dapp with the current version of SDK is deployed here.
Example integration can be found in https://github.com/nufi-official/adaplays.xyz which is a forked/updated version of playground cardano dapp.
We recommend to check usage of @nufi/dapp-client-core
and @nufi/dapp-client-cardano
in File where most of the changes are contained. Alternatively just searching for the usage of these libraries should showcase all relevant steps in the integration.
The other changes made to this repository are specific to its example dapp, so we do not recommend focusing on them.
NPM
Yarn
Make sure that your app's Content Security Policy does not block the iframe that is injected by our SDK. For more info please check iframe injection docs.
The init
function has to be called before calling other functions from @nufi/dapp-client-core
or @nufi/dapp-client-cardano
SDK.
Its advisable to call it as soon as possible as it will also prefetch the Widget, and will make it appear faster when being requested later on.
If no origin is passed to init
it defaults to https://wallet.nu.fi
. Note that this default will not work until officially released.
For now please use the origin from the above example.
To customize Widget appearance (such as z-index, color mode, featured tokens, manual expand or collapse), please see Widget options
Note that the Widget handles cases when users do not have Metamask installed. Therefore its fine to always show some "Login with MetaMask" button on your dapp.
If you nevertheless wish to detect whether the MetaMask is installed, you can do it via the following call:
The initNufiDappCardanoSdk
will populate window.cardano.nufiSnap
object which has methods corresponding to CIP-30 standard.
See multiple providers docs to use initNufiDappCardanoSdk
correctly, when supporting multiple providers.
Use this method to close the Widget in case user logs out using your dapp.
When calling CIP-30 enable
method the Widget will be shown automatically.
Therefore if you detect (possibly a flag in your localStorage) that users is logged in you can simply call the enable
method to make the Widget visible.
For users with NuFi extension installed, there are no specific actions required. Simply access window.cardano.nufi
from anywhere as it is not controlled by the NuFi Widget SDK.
If your Cardano DApp calls getCollateral(), for best UX please make sure to do so only when really needed, otherwise users may get needlessly prompted by the NuFi widget to set up a collateral even if they don't have to. Even better would be to use CIP-40 which lets you use regular inputs as collateral, i.e. removes the need to request collateral explicitly from the wallet.
As an icon for Metamask provider in your dapp, you can download this svg.