Connecting to dApps & Storing Data
Learn how to connect your Nillion Keychain wallet to decentralized applications and securely store encrypted data.
Understanding dApp Connections
When you connect to a dApp (decentralized application), you're giving it permission to:
- Know your DID (Decentralized Identifier)
- Request data storage operations
- Request data retrieval operations
- Manage access permissions
dApps never get access to your private key. They only get your public DID and can request operations that you must approve.
Connecting to a dApp
Step 1: Visit the dApp
Navigate to any Nillion-powered application in your browser. Examples:
- Data storage platforms
- Decentralized identity apps
- Privacy-preserving analytics tools
- Secure messaging apps
Step 2: Click "Connect Wallet"
Look for a button that says:
- "Connect Wallet"
- "Connect to Nillion"
- "Sign In with Nillion"
- Or similar
Step 3: Review the Connection Request
Nillion Keychain will open a popup window showing:
┌─────────────────────────────────────┐
│ Nillion Keychain │
├─────────────────────────────────────┤
│ Approval Request │
│ │
│ Application: example.com │
│ Action: connect │
│ │
│ Only approve actions from │
│ applications you trust. │
│ │
│ [Approve] [Deny] │
└─────────────────────────────────────┘
Review carefully:
- ✅ Check the domain name is correct
- ✅ Verify it's the site you intended to connect to
- ⚠️ Watch for suspicious domains (examp1e.com vs example.com)
Step 4: Approve or Deny
Approve: Click the green "Approve" button if you trust the dApp
Deny: Click the red "Deny" button if:
- You don't recognize the site
- The domain looks suspicious
- You didn't initiate the connection request
If your wallet is locked, you'll see a lock screen first. Enter your password to unlock, then approve the connection.
Step 5: You're Connected!
Once approved:
- ✅ The dApp can see your DID
- ✅ The dApp can request operations (with approval)
- ✅ A success message appears in the dApp
You'll see the site listed in your "Connected Applications" in the Wallet tab.
Storing Data from dApps
How Data Storage Works
When a dApp wants to store data:
- dApp requests storage: "Save this user profile"
- Popup appears: Shows what data will be stored
- You approve: Data is encrypted client-side
- Stored on Nillion: Encrypted data goes to Nillion Network
- You receive ID: Document ID returned for future retrieval
Example: Storing a User Profile
Let's say a dApp wants to store your profile:
Step 1: dApp Requests Storage
The app calls:
await window.nillion.storeData({
collection: "user-profiles",
data: {
_id: "profile-123",
name: "John Doe",
email: "john@example.com",
preferences: {
theme: "dark",
notifications: true,
},
},
});
Step 2: Approval Popup Appears
┌─────────────────────────────────────┐
│ Nillion Keychain │
├─────────────────────────────────────┤
│ Approval Request │
│ │
│ Application: myapp.com │
│ Action: storeData │
│ │
│ Collection: user-profiles │
│ Data: { name, email, preferences } │
│ │
│ Only approve actions from │
│ applications you trust. │
│ │
│ [Approve] [Deny] │
└─────────────────────────────────────┘
Step 3: Review the Request
Check:
- ✅ Is this the data you expect to store?
- ✅ Is the collection name appropriate?
- ✅ Do you trust this application with this data?
Step 4: Approve or Deny
- Approve: Data is encrypted and stored
- Deny: Nothing is stored, operation cancelled
Step 5: Storage Confirmation
After approval:
- Data is encrypted with your keys
- Sent to Nillion Network
- Document ID returned (e.g.,
profile-123) - dApp can use this ID to retrieve data later
What Gets Stored
Data Format:
{
collection: 'user-profiles',
document: 'profile-123',
owner: 'did:nil:0358560d...',
data: {
name: 'John Doe',
email: 'john@example.com',
// ... all other fields
},
_acl: [
]
}
Important Points:
- ✅ Data is encrypted before leaving your browser
- ✅ Nillion nodes never see unencrypted data
- ✅ Only you (and those you grant access) can decrypt it
- ✅ The
_idfield in data becomes the document ID
Retrieving Stored Data
How Data Retrieval Works
When a dApp wants to retrieve data:
- dApp requests data: "Get user profile with ID profile-123"
- Popup appears: Shows what data is being accessed
- You approve: Request sent to Nillion
- Data retrieved: Encrypted data fetched
- Decrypted locally: Data decrypted in your browser
- Returned to dApp: Decrypted data given to dApp
Example: Reading Your Profile
dApp requests:
const data = await window.nillion.retrieveData({
collection: "user-profiles",
document: "profile-123",
});
Approval popup:
┌─────────────────────────────────────┐
│ Nillion Keychain │
├─────────────────────────────────────┤
│ Approval Request │
│ │
│ Application: myapp.com │
│ Action: retrieveData │
│ │
│ Collection: user-profiles │
│ Document: profile-123 │
│ │
│ [Approve] [Deny] │
└─────────────────────────────────────┘
After approval:
- Data fetched from Nillion
- Decrypted in your browser
- Returned to dApp:
{
name: 'John Doe',
email: 'john@example.com',
preferences: { theme: 'dark', notifications: true }
}
Managing Connected dApps
Viewing Connected Applications
- Open Nillion Keychain
- Go to Wallet tab
- Scroll to "Connected Applications"
You'll see a list like:
Connected Applications
├─ myapp.com [×]
├─ demo.nillion.app [×]
└─ analytics.example.com [×]
Disconnecting a dApp
To revoke a dApp's access:
- Find the dApp in "Connected Applications"
- Click the × button
- Confirm: "Disconnect from myapp.com?"
- Click "OK"
What happens after disconnect:
- ✅ dApp can no longer request operations
- ✅ dApp loses access to your DID
- ✅ Existing stored data remains (but dApp can't access it)
- ✅ dApp must request connection again to access
When you disconnect, the dApp is automatically notified and will update its UI to show disconnected state.
Remember: You're always in control. Every operation requires your explicit approval!