Generate Withdraw Code
Request email verification code for user withdrawal operations
Generate Withdraw Code
Request email verification code for secure withdrawal operations
USER Operation
Overview
The generateWithdraw mutation allows users to generate an email verification code required for all withdrawal operations. This is the first step in the withdrawal process and ensures only authorized users can initiate fund withdrawals.
Required for All Withdrawals
This verification code must be obtained before submitting any withdrawal request (crypto, fiat, or PayPal).
GraphQL Schema
generateWithdraw: StringParameters
This mutation does not require any input parameters. The verification code is automatically sent to the email address associated with the authenticated user's account.
Return Value
StringReturns "Success" if the verification code email was sent successfully, otherwise returns an error message.
"Success"Error messageExample Mutation
mutation {
  generateWithdraw
}{
  "data": {
    "generateWithdraw": "Success"
  }
}Use Cases
Generate code before withdrawing cryptocurrency to external wallets
Verify identity before initiating fiat bank withdrawal requests
Secure PayPal withdrawal initiation with email verification
Confirm user identity before any fund withdrawal operations
Implementation Example
// User initiates withdrawal process
async function initiateWithdrawal(amount: number, currency: string) {
  try {
    // Step 1: Generate verification code
    const codeRequest = await client.request(gql`
      mutation {
        generateWithdraw
      }
    `);
    if (codeRequest.generateWithdraw !== 'Success') {
      throw new Error('Failed to send verification code');
    }
    console.log('✅ Verification code sent to your email');
    // Step 2: Prompt user to enter code from email
    const verificationCode = await promptUserForCode();
    // Step 3: Submit withdrawal with verification code
    const withdrawal = await client.request(gql`
      mutation WithdrawCrypto(
        $amount: Float!,
        $sourceToken: String!,
        $network: String!,
        $des: String!,
        $code: String!
      ) {
        cryptoWithdrawRequest(
          amount: $amount,
          sourceToken: $sourceToken,
          network: $network,
          des: $des,
          code: $code
        ) {
          id
          status
          createdAt
        }
      }
    `, {
      amount,
      sourceToken: currency,
      network: 'ERC20',
      des: userWalletAddress,
      code: verificationCode
    });
    console.log('✅ Withdrawal request submitted:', withdrawal);
  } catch (error) {
    console.error('❌ Withdrawal failed:', error);
  }
}Workflow Diagram
Security Features
Code sent only to user's verified email address on file
Verification codes expire after a short time period (typically 10-15 minutes)
Each code can only be used once for a single withdrawal request
User must be authenticated before requesting verification codes
Best Practices
Generate the verification code immediately before filling out the withdrawal form to minimize expiration risk
Inform users to check spam/junk folders if code doesn't arrive within a few minutes
Prevent abuse by limiting how many verification codes can be requested per time period
Show clear success message when code is sent and countdown timer for code expiration
Never store verification codes in browser storage or logs for security
Error Handling
async function generateWithdrawCode() {
  try {
    const result = await client.request(gql`
      mutation {
        generateWithdraw
      }
    `);
    if (result.generateWithdraw === 'Success') {
      showSuccessNotification('Verification code sent to your email');
      startCodeExpirationTimer(15 * 60); // 15 minutes
    } else {
      throw new Error(result.generateWithdraw);
    }
  } catch (error) {
    if (error.message.includes('rate limit')) {
      showErrorNotification('Too many requests. Please wait before requesting another code.');
    } else if (error.message.includes('email')) {
      showErrorNotification('Email delivery failed. Please verify your email address.');
    } else {
      showErrorNotification('Failed to generate verification code. Please try again.');
    }
    console.error('Code generation error:', error);
  }
}Related Operations
Crypto Withdrawal Request
Submit cryptocurrency withdrawal with verification code
Fiat Withdrawal Request
Submit bank transfer withdrawal with verification code
PayPal Withdrawal Request
Submit PayPal withdrawal with verification code
Withdrawal Overview
Complete withdrawal API system documentation