Skip to main content
Version: v1

Connecting wallet

Passport is a valid EIP-1193 provider with support for all major RPC methods.

To create an EIP-1193 Passport provider all you need to do is call await passportInstance.connectEvm() after initialising Passport.

transaction.tsView on GitHub
const provider = await passportInstance.connectEvm();

If you are attempting to create a Passport Provider within a react component, you can use the useEffect hook to create the provider when the component mounts.

// fetch the Passport provider from the Passport instance
const [passportProvider, setPassportProvider] = useState<Provider>();

useEffect(() => {
const fetchPassportProvider = async () => {
const passportProvider = await passportInstance.connectEvm();
setPassportProvider(passportProvider);
};
fetchPassportProvider();
}, []);

Once a EIP-1193 provider is created, you can call various methods on it via the request function (which is protocol-agnostic), for example:

// calling eth_requestAccounts triggers the Passport login flow
const accounts = await passportProvider?.request({ method: 'eth_requestAccounts' });

Calling the eth_requestAccounts request method will trigger the login flow for Passport if the user is not signed in.

Checkout the full working example here: Passport with NextJS Connect with EIP1193.

Provider Events​

As per the EIP-1193 specification, the zkEVM provider exposes an on and removeListener function, which can be used to subscribe to and unsubscribe from events emitted by the zkEVM provider

Supported Events​

Accounts Changed​

The zkEVM provider will emit an accountsChanged event when the accounts available to the provider changes (for example, when eth_requestAccounts is called and the users wallet is initialised):

// listen to the ACCOUNTS_CHANGED event and update the accounts state when it changes
passportProvider?.on(ProviderEvent.ACCOUNTS_CHANGED, (accounts: string[]) => {
setAccountsState(accounts);
});