Fuel Wallet Connectors are an interface provided by wallet developers to allow your DApp to integrate with specific wallets.
You can learn more about how Fuel Wallet Connectors work, by reading the Fuel Wallet Connectors spec.
The Fuel Wallet SDK enables you to include a set of connectors when creating a new instance.
import {
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
} from "@fuels/connectors";
import { Fuel } from "fuels";
const fuel = new Fuel({
connectors: [
new FuelWalletDevelopmentConnector(),
new FueletWalletConnector(),
new FuelWalletConnector(),
],
});
import {
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
} from "@fuels/connectors";
import { Fuel } from "fuels";
const fuel = new Fuel({
connectors: [
new FuelWalletDevelopmentConnector(),
new FueletWalletConnector(),
new FuelWalletConnector(),
],
});
When working with multiple connectors, you should enable users to select the connectors they wish to use for interacting with your DApp. Once the connectors()
method is called, the Fuel Wallet SDK will query information from the connectors, allowing you to determine which connectors are installed.
We also recommend to use the connectors
listener on places that will use the connectors()
method as the availability can change.
const connectors = await fuel.connectors();
console.log("available connectors", connectors);
fuel.on(fuel.events.connectors, (connectors) => {
console.log("available connectors", connectors);
});
Once you have a list of connectors, you can enable the user to select the connector they wish to use by using the selectConnect()
method. If the connector is not installed, the SDK will return false.
const isSelected = await fuel.selectConnector(connectorName);
console.log("isSelected", isSelected);
Once you have selected a connector, you can interact with it using all the available methods.
const connectionState = await fuel.connect();
console.log("connectionState", connectionState);
When using a React application, you can utilize the Connectors UI provided by the React package.
You can see the full a DApp example on the examples folder.
If you prefer to build your own UI for the connectors you achieve the experience using
the hooks useConnect()
and useConnectors()
.
const { connectors } = useConnectors();
const { connect, isPending: connecting, error: errorConnecting } = useConnect();
function handleConnect(connectorName: string) {
connect(connectorName);
}