Skip to content

wallets.getByAddress()

Retrieve a wallet profile by its Ethereum address.

Signature

wallets.getByAddress(address: string): Promise<Wallet>

Parameters

address

  • Type: string
  • Required: Yes
  • Format: Ethereum address (0x-prefixed, 42 characters)

The Ethereum wallet address.

Returns

  • Type: Promise<Wallet>
interface Wallet {
  id: string;
  wallet_address: string;
  wallet_address_network: WalletNetwork;
  username: string | null;
  picture_url: string | null;
  created_at: number;
  updated_at: number;
}

Usage

Basic Example

const wallet = await grapevine.wallets.getByAddress(
  '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'
);
 
console.log('Wallet ID:', wallet.id);
console.log('Username:', wallet.username || 'Not set');
console.log('Created:', new Date(wallet.created_at * 1000));

From Connected Wallet

// In a React app with wagmi
import { useAccount } from 'wagmi';
 
function UserProfile() {
  const { address } = useAccount();
  const [profile, setProfile] = useState(null);
  
  useEffect(() => {
    if (address) {
      grapevine.wallets.getByAddress(address)
        .then(setProfile)
        .catch(console.error);
    }
  }, [address]);
  
  if (!profile) return <div>Loading...</div>;
  
  return (
    <div>
      <h2>{profile.username || 'Anonymous'}</h2>
      {profile.picture_url && <img src={profile.picture_url} alt="Avatar" />}
    </div>
  );
}

Check if Wallet Exists

async function walletExists(address: string): Promise<boolean> {
  try {
    await grapevine.wallets.getByAddress(address);
    return true;
  } catch (error) {
    if (error.message.includes('404')) {
      return false;
    }
    throw error;
  }
}

Get Wallet with Stats

async function getFullWalletProfile(address: string) {
  const wallet = await grapevine.wallets.getByAddress(address);
  const stats = await grapevine.wallets.getStats(wallet.id);
  
  return {
    ...wallet,
    stats
  };
}
 
// Usage
const profile = await getFullWalletProfile('0x742d35Cc...');
console.log('Total revenue:', profile.stats.total_revenue_earned);

Validation

The SDK validates the address format before making the request:

// ✅ Valid formats
await grapevine.wallets.getByAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb');
 
// ❌ Invalid - missing 0x prefix
await grapevine.wallets.getByAddress('742d35Cc6634C0532925a3b844Bc9e7595f0bEb');
// Error: Invalid wallet address format
 
// ❌ Invalid - wrong length
await grapevine.wallets.getByAddress('0x742d35');
// Error: Invalid wallet address format

Error Handling

try {
  const wallet = await grapevine.wallets.getByAddress(address);
  console.log('Found wallet:', wallet);
} catch (error) {
  if (error.message.includes('Invalid wallet address')) {
    console.error('Invalid address format - must be 0x followed by 40 hex characters');
  } else if (error.message.includes('404')) {
    console.error('No wallet found for this address');
  } else {
    console.error('Error:', error.message);
  }
}

Notes

  • Authentication: Not required - public endpoint
  • Address Validation: Must be valid Ethereum address format (0x + 40 hex chars)
  • Case Sensitivity: Addresses are case-insensitive (checksummed or lowercase both work)
  • Auto-Created: Wallets are created automatically when a user first interacts with the platform

Related