API Examples: TypeScript Examples

Here are some examples of how you can use the io.vault API with TypeScript and the fetch function:

// GraphQL query for retrieving vaults
const query = `
  query {
    vaults {
      id
      name
      description
      status
      threshold
    }
  }
`;

// Mutation for creating a new vault
const mutation = `
  mutation {
  createVault(
    name: "My New Vault"
    description: "A vault for my most important assets"
    signingParty: {
      threshold: 2
      signers: [
        {
          weight: 1
          deviceId: "cl1qzm9ue0183yk6lhds8wp2e"
        },
        {
          weight: 1
          deviceId: "cl1qzm9ue0183yk6lhds8wp2f"
        }
      ]
    }
  ) {
    id
    status
  }
}
`;

// Example of setting up headers for the API request
const headers = {
  'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
  'Content-Type': 'application/json'
};

// Fetch function for sending the request
async function sendRequest() {
  const response = await fetch('https://api.io.vault', {
    method: 'POST',
    headers: headers,
    body: JSON.stringify({ query: query })
  });
  const data = await response.json();
  console.log(data);
}

sendRequest();