Skip to content

Instantly share code, notes, and snippets.

Last active January 26, 2023 20:38
What would you like to do?
Vanilla JS Example for Compound Extension for Comet
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vanilla Compound Extension</title>
<body style="background: #FFF;">
<h1>Compound Extension Example</h1>
<p>Embedded iFrame</p>
<p id="status"></p>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></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 ='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.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment