Skip to content

Instantly share code, notes, and snippets.

Last active May 9, 2023 19:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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');
statusElement.innerText = 'Not currently connected to the Compound app.';
let provider;
if (!embedded) {
provider = new ethers.providers.Web3Provider(window.ethereum);
} else {
let rpc = new CometExtension.buildRPC();
provider = new CometExtension.RPCWeb3Provider(rpc.sendRPC);
rpc.sendRPC({ type: 'getSelectedMarket' }).then(({ selectedMarket }) => {
console.log('selectedMarket', selectedMarket);
// selectedMarket {
// "chainId": 1,
// "baseAssetSymbol": "USDC",
// "marketAddress": "0xc3d688B66703497DAA19211EEdff47f25384cdc3"
// }
statusElement.innerText = 'Connected to parent app successfully.';
} else {
statusElement.innerText = 'No web3 provider.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment