OmnesMSA API Docs
Examples

JavaScript Examples

Complete JavaScript examples for calling the MSA API directly using HTTP fetch.

Complete JavaScript examples for calling the MSA API directly using HTTP fetch. These examples use native browser APIs to make direct API calls - there is no JavaScript SDK, only the TypeScript SDK is available.

Setup

const MSA_CONFIG = {
  baseURL: 'https://api.msa.omnes.tech',
  apiKey: 'your-api-key-here',
  settings: {
    rpc: 'https://rpc-amoy.polygon.technology/',
    factory: '0xb09Fd1134553a43A3E02182a6B04F4dEBa7476F4',
    validator: '0x9bD18Da66990F80d598dE02d5143dC9A4422eC3a',
    entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
    beaconAdminAddress: '0x99Ee7725D6a8f691d8B375e0aD33d1Aff2236618'
  }
};

const CUSTODY_TYPES = {
  ECDSA_VALIDATOR: 1,
  ECDSA_PASSKEY_VALIDATOR: 2,
  PASSKEY_VALIDATOR: 3,
  MULTISIG_VALIDATOR: 4,
  MULTISIG_PASSKEY_VALIDATOR: 5
};

Wallet Operations

Predict Wallet Address

async function predictWallet(salt) {
  const response = await fetch(`${MSA_CONFIG.baseURL}/predict`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      accounts: [{
        walletCustody: CUSTODY_TYPES.ECDSA_VALIDATOR,
        salt: salt
      }],
      settings: MSA_CONFIG.settings
    })
  });
  
  const result = await response.json();
  return result.predictions[0].wallet;
}

// Usage
const walletAddress = await predictWallet('user@example.com');
console.log('Predicted address:', walletAddress);

Create Wallet

async function createWallet(salt, signer) {
  const response = await fetch(`${MSA_CONFIG.baseURL}/create`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      accounts: [{
        walletCustody: CUSTODY_TYPES.ECDSA_VALIDATOR,
        salt: salt
      }],
      settings: {
        ...MSA_CONFIG.settings,
        beaconAdminCreationCode: '0x60a060405260405161059d...',
        signer: {
          clientId: signer.clientId,
          versionId: signer.versionId
        }
      }
    })
  });
  
  const result = await response.json();
  return result;
}

// Usage
const result = await createWallet('user@example.com', {
  clientId: 'your-client-id',
  versionId: '1'
});
console.log('Wallet created:', result.returnData[0]['0'].wallet);

Check Wallet

async function checkWallet(salt) {
  const response = await fetch(`${MSA_CONFIG.baseURL}/check`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      accounts: [{
        walletCustody: CUSTODY_TYPES.ECDSA_VALIDATOR,
        salt: salt
      }],
      settings: MSA_CONFIG.settings
    })
  });
  
  const result = await response.json();
  return result.results[0];
}

// Usage
const check = await checkWallet('user@example.com');
if (check.exists) {
  console.log('Wallet exists:', check.wallet);
}

Transaction Execution

Execute Transaction

async function executeTransaction(operation, signer) {
  const response = await fetch(`${MSA_CONFIG.baseURL}/execute`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      operations: [operation],
      settings: {
        ...MSA_CONFIG.settings,
        signer: {
          clientId: signer.clientId,
          versionId: signer.versionId
        }
      }
    })
  });
  
  const result = await response.json();
  return result;
}

// Usage
const txResult = await executeTransaction({
  walletCustody: CUSTODY_TYPES.ECDSA_VALIDATOR,
  salt: 'user@example.com',
  to: '0x097d4Aed5924e2172451973153Fc0e03407eD1F9',
  funcSignature: 'transfer(address,uint256)',
  funcParams: [
    '0xRecipientAddress...',
    '1000000000000000000'
  ]
}, {
  clientId: 'your-client-id',
  versionId: '1'
});

console.log('Transaction hash:', txResult.txHash);

Complete Workflow

async function completeWalletWorkflow(userSalt, signer) {
  try {
    // 1. Predict
    console.log('Predicting wallet...');
    const walletAddress = await predictWallet(userSalt);
    console.log('Predicted address:', walletAddress);
    
    // 2. Check
    console.log('Checking wallet...');
    const check = await checkWallet(userSalt);
    
    if (!check.exists) {
      // 3. Create
      console.log('Creating wallet...');
      const createResult = await createWallet(userSalt, signer);
      console.log('Wallet created:', createResult.txHash);
    } else {
      console.log('Wallet already exists');
    }
    
    // 4. Execute
    console.log('Executing transaction...');
    const txResult = await executeTransaction({
      walletCustody: CUSTODY_TYPES.ECDSA_VALIDATOR,
      salt: userSalt,
      to: '0x097d4Aed5924e2172451973153Fc0e03407eD1F9',
      funcSignature: 'transfer(address,uint256)',
      funcParams: ['0xRecipient...', '1000000']
    }, signer);
    
    console.log('Transaction sent:', txResult.txHash);
    
    return {
      wallet: walletAddress,
      created: !check.exists,
      txHash: txResult.txHash
    };
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}

Error Handling

async function safeExecute(operation, signer) {
  try {
    const result = await executeTransaction(operation, signer);
    
    if (result.status === 1) {
      return { success: true, txHash: result.txHash };
    } else {
      return { success: false, errors: result.errors };
    }
  } catch (error) {
    if (error.message.includes('insufficient funds')) {
      console.error('Wallet needs more funds');
    } else if (error.message.includes('Invalid client ID')) {
      console.error('Check your Fireblocks credentials');
    } else {
      console.error('Transaction failed:', error.message);
    }
    return { success: false, error: error.message };
  }
}

Next Steps


💡 Tip: Use the TypeScript SDK for better type safety and IntelliSense support in your JavaScript projects.