Multi-Chain Connect
DID Connect is designed with interoperability in mind, extending its capabilities beyond the ArcBlock ecosystem. You can configure it to seamlessly interact with other major blockchains, such as Ethereum and Solana. This example demonstrates how to set up a DID Connect session to request actions on the Ethereum network.
The key to multi-chain functionality is the chainInfo object, which tells the user's wallet which network to connect to for the session.
The chainInfo Object#
To initiate a request on a specific blockchain, you must provide a chainInfo object. This object specifies the target network's type, ID, and connection endpoint.
Here are the fields for the chainInfo object:
Field | Type | Description | Required |
|---|---|---|---|
| string | The type of blockchain. Supported values are | Yes |
| string | The network's Chain ID. For example, | For |
| string | The RPC endpoint for the network. While optional, it's highly recommended for reliable communication. | No |
Example: Requesting a Signature on Ethereum#
Let's walk through an example of how to request a user to sign a message using their Ethereum account on the Sepolia testnet.
First, define the chainInfo for the target network. This object will be passed to WalletHandlers to configure the DID Connect session.
Ethereum Chain Configuration
const ethereumChainInfo = {
type: 'ethereum',
id: '11155111', // Sepolia Chain ID
host: 'https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID', // Example RPC endpoint
};Next, use this configuration within the handlers.attach method. You can set the chainInfo in the authPrincipal claim to define the context for the entire session. You can also specify it for individual claims if you need to orchestrate a workflow across multiple chains.
Attaching Wallet Handlers
const { WalletHandlers } = require('@arcblock/did-connect');
// Assuming 'authenticator' and 'tokenStorage' are already configured
const handlers = new WalletHandlers({ authenticator, tokenStorage });
handlers.attach({
app: server, // Your Express.js app instance
action: 'eth-signature',
// Set the chain context for the entire authentication request
authPrincipal: {
chainInfo: ethereumChainInfo,
},
// Define the claims to be requested on the specified chain
claims: {
signature: () => ({
typeUrl: 'eth:personal-data', // Request a personal signature
display: 'Sign a message to verify your Ethereum account',
origin: 'https://yourapp.com',
// This is optional if authPrincipal.chainInfo is set
chainInfo: ethereumChainInfo,
}),
},
See all 8 lines
How It Works#
- When your application generates the DID Connect QR code, it will be encoded with the Ethereum
chainInfoyou provided. - The user scans the QR code with a compatible wallet like ABT Wallet.
- The wallet recognizes the
type: 'ethereum'and prompts the user to switch to the Sepolia Ethereum network. - The user is then asked to sign the message using their selected Ethereum account.
- Upon approval, the wallet sends the signature back to your application, which you can then process in the
onAuthcallback.
This same pattern can be applied to other chains like Solana by simply changing the chainInfo object accordingly. This powerful feature allows you to build decentralized applications that leverage identities and assets across multiple blockchain ecosystems.