Integration instructions
Integrates your DApp with the NuFi web wallet injected into it is as a widget. Users can seamlessly onboard/log in into your DApp using social providers such as Google, Facebook or Discord while being able to manage their wallet in the NuFi interface.
Demo
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
, @nufi/dapp-client-cardano
and @nufi/sso-button-react
in File 1 and File 2 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.
Install packages
NPM
Yarn
Usage
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.
Initialize core SDK
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
.
To customize Widget appearance (such as z-index, color mode, featured tokens, manual expand or collapse), please see Widget options
Initialize SSO login for Cardano
When called like in the example above users will be asked to choose Web3Auth provider inside the NuFi Widget. If you want to choose specific provider you can pass it using provider
parameter like this:
You can currently choose google
, facebook
and discord
providers.
The initNufiDappCardanoSdk
will populate window.cardano.nufiSSO
object which has methods corresponding to CIP-30 standard.
See multiple providers docs to use initNufiDappCardanoSdk
correctly, when supporting multiple providers.
Listening to social login info changes
You can listen to the changes of current social login info using the following:
Alternatively you can call:
The returned data is either null
or of the following type
HideWidget
Use this method to close the Widget in case user logs out using your dapp.
Show widget
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.
Use SsoButton for React
You can use the @nufi/dapp-client-core
and @nufi/dapp-client-cardano
with any JS framework, though in case you are using React we prepared a simple Social login button widget that you can use out of the box.
You can always use the SDK with you custom Button widget.
NPM
Yarn
For a complete example please check here.
You can find the assets for the Login button here.
Button position
For seamless user navigation, it is recommended that the Login button be positioned in the top bar, to the left of the Wallet selection options.
If the DApp UI does not allow this, the Login button can be placed inside the Wallet selection options as the top option.
\
Selecting Extension provider
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.
Note on Cardano Collaterals
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.
Whitelist
NuFiConnect mainnet
To integrate the widget on mainnet, your DApp's domain needs need to be whitelisted. Please contact us and specify the domains to be whitelisted.
Note that localhost
with any port is supported by default.
Last updated