Pairing code authentication lets you link Baileys to WhatsApp using an 8-digit code instead of a QR code. This is useful in headless environments where displaying a QR code is inconvenient, or when you want to link a device by entering a code on your phone manually.Documentation Index
Fetch the complete documentation index at: https://whiskeysockets-docs-jids-socket-config-ptbr.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Setup
Create the socket
Create the socket without rendering a QR code. You can simply ignore the
qr field on connection.update while using pairing codes.The legacy
printQRInTerminal option is deprecated and should not be set. Don’t render the QR string while pairing by code — just call requestPairingCode instead.Request a pairing code
Check The returned
sock.authState.creds.registered before requesting a code. If the socket is already registered (i.e., credentials are already present from a previous session), you do not need to request a new code.code is an 8-digit string you enter on your phone.Phone number format
The phone number you pass torequestPairingCode must follow these rules:
- Include the country code (e.g.,
1for the US,44for the UK) - Use digits only — no
+,(,), or-characters - Do not include spaces
Complete example
The following example usesreadline to prompt for the phone number at runtime, matching the pattern used in the official example script.
The
qr field in connection.update fires even in pairing code mode. Use it as your trigger to call requestPairingCode rather than calling it immediately after creating the socket, because the socket may not be ready yet.