Creating/Deleting Blockchains
You can manage your blockchains through the UI at mirror.ad or via API
Creating a Mirror instance
Use this endpoint to create a new Mirror instance. You can use the mirror url in any place you would use an RPC URL. On the free beta, you are allowed up to 10 Mirror instances. Don't fret though because you can delete unused instances at will!
async function getRpcUrl(): Promise<string> {
const mirrorApiKey = process.env.MIRROR_API_KEY;
try {
const response = await fetch("https://engine.mirror.ad/blockchains", {
method: "POST",
headers: {
api_key: mirrorApiKey,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
});
if (response.status !== 200) {
throw new Error(`Error getting RPC URL: ${response.status}`);
}
const data = (await response.json()) as { url: string };
return data.url;
} catch (error) {
console.error("Error:", error);
throw error;
}
}
Deleting a Mirror instance
Deleting a mirror-chain instance is incredibly easy!
async function clearMirrorchain(rpcUrl: string): Promise<void> {
const mockchainApiKey = process.env.MIRROR_API_KEY;
try {
const response = await fetch(rpcUrl, {
method: "DELETE",
headers: {
api_key: mockchainApiKey,
"Content-Type": "application/json",
},
});
const body = await response.text();
if (response.status !== 200) {
throw new Error(`Error clearing mockchain: ${body}`);
}
} catch (error) {
console.error("Error:", error);
throw error;
}
}
Last updated