wallets.update()
Update a wallet's profile information (username, profile picture).
Signature
wallets.update(walletId: string, input: UpdateWalletInput): Promise<Wallet>Parameters
walletId
- Type:
string - Required: Yes
- Format: UUID
The unique identifier of the wallet to update.
input
- Type:
UpdateWalletInput
interface UpdateWalletInput {
username?: string; // Display name
picture_url?: string; // Profile picture URL
}Returns
- Type:
Promise<Wallet>
The updated wallet object.
Usage
Update Username
const myWallet = await grapevine.wallets.getMe();
const updated = await grapevine.wallets.update(myWallet.id, {
username: 'cryptoexpert'
});
console.log('New username:', updated.username);Update Profile Picture
const myWallet = await grapevine.wallets.getMe();
const updated = await grapevine.wallets.update(myWallet.id, {
picture_url: 'https://example.com/avatar.png'
});
console.log('New picture:', updated.picture_url);Update Both
const myWallet = await grapevine.wallets.getMe();
const updated = await grapevine.wallets.update(myWallet.id, {
username: 'alice_trader',
picture_url: 'https://example.com/alice-avatar.jpg'
});
console.log('Profile updated:', {
username: updated.username,
picture: updated.picture_url
});Profile Setup Flow
async function setupProfile(username: string, pictureUrl?: string) {
try {
// Get current wallet
const myWallet = await grapevine.wallets.getMe();
// Build update input
const input: UpdateWalletInput = { username };
if (pictureUrl) {
input.picture_url = pictureUrl;
}
// Update profile
const updated = await grapevine.wallets.update(myWallet.id, input);
console.log('✅ Profile updated successfully');
return updated;
} catch (error) {
if (error.message.includes('409')) {
throw new Error('Username already taken');
}
if (error.message.includes('400')) {
throw new Error('Invalid username or picture URL');
}
throw error;
}
}React Form Example
function ProfileEditor() {
const [username, setUsername] = useState('');
const [pictureUrl, setPictureUrl] = useState('');
const [saving, setSaving] = useState(false);
const [error, setError] = useState('');
const grapevine = useGrapevine({ walletClient, network: 'testnet' });
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setSaving(true);
setError('');
try {
const myWallet = await grapevine.wallets.getMe();
await grapevine.wallets.update(myWallet.id, {
username: username || undefined,
picture_url: pictureUrl || undefined
});
alert('Profile updated!');
} catch (err) {
if (err.message.includes('409')) {
setError('Username already taken');
} else if (err.message.includes('400')) {
setError('Invalid input - check username format');
} else {
setError(err.message);
}
} finally {
setSaving(false);
}
};
return (
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
pattern="[a-zA-Z0-9_]+"
title="Letters, numbers, and underscores only"
/>
<input
type="url"
placeholder="Profile Picture URL"
value={pictureUrl}
onChange={(e) => setPictureUrl(e.target.value)}
/>
{error && <p className="error">{error}</p>}
<button type="submit" disabled={saving}>
{saving ? 'Saving...' : 'Update Profile'}
</button>
</form>
);
}Validation
Username Rules
- Must be a non-empty string (if provided)
- Alphanumeric characters and underscores only
- Case-insensitive for uniqueness checks
Picture URL Rules
- Must be a valid HTTP/HTTPS URL
- Must be publicly accessible
- Data URLs are not supported
// ✅ Valid
await grapevine.wallets.update(walletId, {
username: 'alice_trader123',
picture_url: 'https://example.com/avatar.png'
});
// ❌ Invalid username
await grapevine.wallets.update(walletId, {
username: 'alice@trader' // No special characters
});
// ❌ Invalid picture URL
await grapevine.wallets.update(walletId, {
picture_url: 'data:image/png;base64,...' // No data URLs
});Error Handling
try {
const updated = await grapevine.wallets.update(walletId, input);
console.log('Profile updated:', updated);
} catch (error) {
if (error.message.includes('401')) {
console.error('Not authenticated - configure wallet first');
} else if (error.message.includes('403')) {
console.error('Can only update your own wallet');
} else if (error.message.includes('409')) {
console.error('Username already taken');
} else if (error.message.includes('400')) {
console.error('Invalid input format');
} else {
console.error('Error:', error.message);
}
}Notes
- Authentication: Required - must be wallet owner
- Ownership: Can only update your own wallet profile
- Username Uniqueness: Usernames must be unique across the platform
- Partial Updates: Only provided fields are updated; omitted fields remain unchanged
Related
- wallets.getMe() - Get current wallet
- wallets.get() - Get wallet by ID
- API: Update Wallet - REST API reference