Skip to content

Commit

Permalink
Add script for deploying Keplr chain configs
Browse files Browse the repository at this point in the history
Create a go script for bringing up a server for
deploying Monomer devnet chain configs on Keplr.
  • Loading branch information
natebeauregard committed Oct 9, 2024
1 parent 468d920 commit b295a2d
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ e2e:
-l1-deployments ./optimism/.devnet/addresses.json \
-deploy-config ./optimism/packages/contracts-bedrock/deploy-config/devnetL1.json

.PHONY: keplr-integration
keplr-integration:
go run github.com/eliben/[email protected] -port=0 e2e/keplr

.PHONY: install-golangci-lint
install-golangci-lint:
go install github.com/golangci/golangci-lint/cmd/[email protected]
Expand Down
65 changes: 65 additions & 0 deletions e2e/keplr/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Keplr Integration</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
text-align: center;
background-color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

h1 {
font-size: 2rem;
color: #333;
margin-bottom: 20px;
}

button {
background-color: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #0056b3;
}
</style>
<script src="keplr-integration.js?v=1.0" defer></script>
</head>
<body>
<div class="container">
<h1>Monomer Devnet Keplr Integration</h1>
<button id="enable-keplr">Enable Keplr</button>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const enableKeplrButton = document.getElementById("enable-keplr");
enableKeplrButton.addEventListener("click", function() {
runKeplrIntegration();
});
});
</script>
</body>
</html>
125 changes: 125 additions & 0 deletions e2e/keplr/keplr-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const L1_CHAIN_CONFIG = {
chainId: "eip155:900",
chainName: "Ethereum (Monomer Devnet)",
rpc: "http://127.0.0.1:44601",
rest: "http://127.0.0.1:44601",
stakeCurrency: {
coinDenom: "ETH",
coinMinimalDenom: "wei",
coinDecimals: 18,
coinGeckoId: "ethereum",
},
bip44: {
coinType: 60,
},
evm: {
chainId: "900",
rpc: "http://127.0.0.1:44601",
},
currencies: [
{
coinDenom: "ETH",
coinMinimalDenom: "wei",
coinDecimals: 18,
},
],
feeCurrencies: [
{
coinDenom: "ETH",
coinMinimalDenom: "wei",
coinDecimals: 18,
},
],
gasPriceStep: {
low: 0.00000002, // Minimum gas price (in ETH) for transactions (20 Gwei)
average: 0.00000005, // Average gas price (50 Gwei)
high: 0.0000001, // High gas price (100 Gwei)
},
features: ["eth-address-gen", "eth-key-sign"],
}

const L2_CHAIN_CONFIG = {
chainId: "1",
chainName: "L2 (Monomer Devnet)",
rpc: "http://127.0.0.1:26657",
rest: "http://127.0.0.1:1317",
stakeCurrency: {
coinDenom: "STAKE",
coinMinimalDenom: "stake",
coinDecimals: 6,
},
bip44: {
coinType: 118,
},
bech32Config: {
bech32PrefixAccAddr: "cosmos",
bech32PrefixAccPub: "cosmospub",
bech32PrefixValAddr: "cosmosvaloper",
bech32PrefixValPub: "cosmosvaloperpub",
bech32PrefixConsAddr: "cosmosvalcons",
bech32PrefixConsPub: "cosmosvalconspub",
},
currencies: [
{
coinDenom: "STAKE",
coinMinimalDenom: "stake",
coinDecimals: 6,
},
],
feeCurrencies: [
{
coinDenom: "STAKE",
coinMinimalDenom: "stake",
coinDecimals: 6,
},
],
gasPriceStep: {
low: 0.01,
average: 0.025,
high: 0.03,
},
}

async function runKeplrIntegration() {
try {
// Register the chains with Keplr
await registerChainsWithKeplr();

// Enable L1 and L2 chains in Keplr
await enableKeplr(L1_CHAIN_CONFIG.chainId);
await enableKeplr(L2_CHAIN_CONFIG.chainId);

console.log("Keplr is now interacting with the e2e test chains");
} catch (err) {
console.error("Error interacting with Keplr:", err);
}
}

async function enableKeplr(chainId) {
if (!window.keplr) {
console.error("Keplr wallet is not installed");
return;
}
// Enable the chain with Keplr
await window.keplr.enable(chainId.toString());
const offlineSigner = window.getOfflineSigner(chainId.toString());
const accounts = await offlineSigner.getAccounts();
console.log("Connected accounts:", accounts);
}

async function registerChainsWithKeplr() {
if (!window.keplr) {
console.error("Keplr wallet is not installed");
return;
}

try {
await window.keplr.experimentalSuggestChain(L1_CHAIN_CONFIG);

await window.keplr.experimentalSuggestChain(L2_CHAIN_CONFIG);

alert("L1 and L2 chains registered with Keplr");
} catch (error) {
console.error("Error registering chains:", error);
}
}

0 comments on commit b295a2d

Please sign in to comment.