Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active January 26, 2023 20:38
Embed
What would you like to do?
Vanilla JS Example for Compound Extension for Comet
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vanilla Compound Extension</title>
</head>
<body style="background: #FFF;">
<h1>Compound Extension Example</h1>
<p>Embedded iFrame</p>
<p id="status"></p>
</body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ethers@5.7.2/dist/ethers.umd.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@compound-finance/comet-extension@0.0.13/dist/index.browser.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', async () => {
const statusElement = document.getElementById('status');
if (window.ethereum) {
// be sure to add ?embedded=true query param to the end of your extension source URL
const embedded = window.location.search.includes('embedded');
let rpc = new CometExtension.buildRPC();
let provider;
if (!embedded) {
provider = new ethers.providers.Web3Provider(window.ethereum);
statusElement.innerText = 'Not currently connected to the parent app.';
} else {
provider = new CometExtension.RPCWeb3Provider(rpc.sendRPC);
statusElement.innerText = 'Connected to parent app successfully.';
}
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment