Overview
Below are the most common types in Magic’s TypeScript SDK, separated by module. To view all supported types, feel free to explore the Magic SDK repo.User Module
MagicUserMetadata
TypeScript
Copy
Ask AI
export interface MagicUserMetadata {
issuer: string | null;
publicAddress: string | null;
email: string | null;
phoneNumber: string | null;
isMfaEnabled: boolean;
recoveryFactors: [RecoveryFactor];
}
RecoveryMethodType
TypeScript
Copy
Ask AI
export enum RecoveryMethodType {
PhoneNumber = 'phone_number',
}
RecoveryFactor
TypeScript
Copy
Ask AI
type RecoveryFactor = {
type: RecoveryMethodType;
value: string;
};
GetIdTokenConfiguration
TypeScript
Copy
Ask AI
export interface GetIdTokenConfiguration {
/*
* The number of seconds until the generated ID token will expire.
*/
lifespan?: number;
}
GenerateIdTokenConfiguration
TypeScript
Copy
Ask AI
export interface GenerateIdTokenConfiguration extends GetIdTokenConfiguration {
/*
* An optional piece of data to sign with the token. Note, however, that the
* unsigned data _will not_ be encoded in the token, only an encrypted
* signature of the data.
*/
attachment?: string;
}
UpdateEmailConfiguration
TypeScript
Copy
Ask AI
export interface UpdateEmailConfiguration {
/*
* The new email address to update to
*/
email: string;
/*
* When `true`, a pre-built pending modal interface will
* guide the user to check their new, followed by old emails
* for confirmation emails.
*/
showUI?: boolean;
}
RecoverAccountConfiguration
TypeScript
Copy
Ask AI
export interface RecoverAccountConfiguration {
/*
* The email to recover
*/
email: string;
}
ShowSettingsConfiguration
TypeScript
Copy
Ask AI
export interface ShowSettingsConfiguration {
/*
* deep linking destination
*/
page: DeepLinkPage;
}
Wallet Module
GasApiResponse
TypeScript
Copy
Ask AI
export type GasApiResponse = {
request_id: string;
state: string;
success: boolean;
};
AccessListEntry
TypeScript
Copy
Ask AI
export type AccessListEntry = { address: string; storageKeys: Array<string> };
AccessList
TypeScript
Copy
Ask AI
export type AccessList = Array<AccessListEntry>;
Auth Module
LoginWithSmsConfiguration
TypeScript
Copy
Ask AI
export interface LoginWithSmsConfiguration {
/*
* Specify the phone number of the user attempting to login.
*/
phoneNumber: string;
}
LoginWithEmailOTPConfiguration
TypeScript
Copy
Ask AI
export interface LoginWithEmailOTPConfiguration {
/*
* Specify the email address of the user attempting to login.
*/
email: string;
/*
* When `true`, a pre-built modal interface will show to the user, directing
* them to check their email for the one time passcode (OTP) to complete their
* authentication.
*
* When `false`, developers will be able to implement their own custom UI to
* continue the email OTP flow.
*/
showUI?: boolean;
/*
* Device Unrecognized UI will enforce showing up to secure user's login
*
* When set to true (default), an improved device recognition UI will be displayed to the user,
* prompting them to verify their login by checking their email for device approval. This feature
* enhances authentication security.
*
* This param will only be affect if showUI is false. When set to false,
* developers have the flexibility to implement their own customized UI to
* handle device check events, providing a more tailored user experience.
*/
deviceCheckUI?: boolean;
/*
* Enterprise users with a custom SMTP can create custom email templates
* from their dashboard. The default Magic loginWithOTP email will be
* overriden when a variation is passed here.
*/
overrides?: {
variation?: string;
};
}
EventHandlers
TypeScript
Copy
Ask AI
export type LoginWithMagicLinkEventHandlers = {
// Event Received
[LoginWithMagicLinkEventOnReceived.EmailSent]: () => void;
[LoginWithMagicLinkEventOnReceived.EmailNotDeliverable]: () => void;
// Event sent
[LoginWithMagicLinkEventEmit.Retry]: () => void;
} & DeviceVerificationEventHandlers;
export type LoginWithEmailOTPEventHandlers = {
// Event Received
[LoginWithEmailOTPEventOnReceived.EmailOTPSent]: () => void;
[LoginWithEmailOTPEventOnReceived.InvalidEmailOtp]: () => void;
[LoginWithEmailOTPEventOnReceived.ExpiredEmailOtp]: () => void;
// Event sent
[LoginWithEmailOTPEventEmit.VerifyEmailOtp]: (otp: string) => void;
[LoginWithEmailOTPEventEmit.Cancel]: () => void;
} & DeviceVerificationEventHandlers;
type DeviceVerificationEventHandlers = {
// Event Received
[DeviceVerificationEventOnReceived.DeviceNeedsApproval]: () => void;
[DeviceVerificationEventOnReceived.DeviceVerificationEmailSent]: () => void;
[DeviceVerificationEventOnReceived.DeviceVerificationLinkExpired]: () => void;
[DeviceVerificationEventOnReceived.DeviceApproved]: () => void;
// Event sent
[DeviceVerificationEventEmit.Retry]: () => void;
};
Auth Events Enum
TypeScript
Copy
Ask AI
export enum LoginWithMagicLinkEventEmit {
Retry = 'retry',
}
export enum LoginWithMagicLinkEventOnReceived {
EmailSent = 'email-sent',
EmailNotDeliverable = 'email-not-deliverable',
}
export enum LoginWithEmailOTPEventEmit {
VerifyEmailOtp = 'verify-email-otp',
Cancel = 'cancel',
}
export enum LoginWithEmailOTPEventOnReceived {
EmailOTPSent = 'email-otp-sent',
InvalidEmailOtp = 'invalid-email-otp',
ExpiredEmailOtp = 'expired-email-otp',
}
export enum DeviceVerificationEventEmit {
Retry = 'device-retry',
}
export enum DeviceVerificationEventOnReceived {
DeviceApproved = 'device-approved',
DeviceNeedsApproval = 'device-needs-approval',
DeviceVerificationLinkExpired = 'device-verification-link-expired',
DeviceVerificationEmailSent = 'device-verification-email-sent',
}
NFT Module
NFTPurchaseRequest
TypeScript
Copy
Ask AI
export interface NFTPurchaseRequest {
nft: {
name: string;
imageUrl: string;
blockchainNftId: string;
contractAddress: string;
network: string;
platform: string;
type: string;
};
identityPrefill: {
firstName: string;
lastName: string;
dateOfBirth: string; // YYYY-MM-DD
emailAddress: string;
phone: string;
address: {
street1: string;
street2: string;
city: string;
regionCode: string;
postalCode: string;
countryCode: string;
};
};
}
NFTCheckoutRequest
TypeScript
Copy
Ask AI
export interface NFTCheckoutRequest {
// given by magic / found in the developer dashboard in future
contractId: string;
// in contract, if ERC1155… for ERC721, use token ID = 0
tokenId: string;
name: string;
imageUrl: string;
quantity?: number; // default is 1
walletAddress?: string; // default is user's wallet address
}
NFTTransferRequest
TypeScript
Copy
Ask AI
export interface NFTTransferRequest {
tokenId: string;
contractAddress: string;
quantity?: number;
recipient?: string;
}
Responses and ResponseStatus
TypeScript
Copy
Ask AI
export type NFTResponseStatus = 'cancelled' | 'processed' | 'declined' | 'expired';
export type NFTResponse = {
status: NFTResponseStatus;
};
export type NFTPurchaseResponse = NFTResponse & {
errorMessage?: string;
};
export type NFTCheckoutResponse = NFTResponse;
export type NFTTransferResponse = NFTResponse;