Skip to content

Commit

Permalink
feat: Add ENS resolution
Browse files Browse the repository at this point in the history
A section has been added for resolving ENS addresses. This was made to
assist with reproducing this bug: MetaMask/eth-json-rpc-middleware#335
  • Loading branch information
legobeat authored and Gudahtt committed Oct 10, 2024
1 parent f417d01 commit 3216e2a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,37 @@ <h4 class="card-title">
</div>
</div>
</section>
<section>
<div class="row d-flex justify-content-center">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">
ENS Resolution
</h4>
<div class="form-group">
<label>Address</label>
<input
class="form-control"
type="text"
id="ensInput"
/>
</div>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="ensSubmit"
>
Submit
</button>
<p class="info-text alert alert-warning">
Result:
<span id="ensResult"></span>
</p>
</div>
</div>
</div>
</div>
</section>
</main>

<script src="main.js" defer></script>
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ const maliciousPermitHexPaddedChain = document.getElementById(
const maliciousPermitIntAddress = document.getElementById(
'maliciousPermitIntAddress',
);

// ENS Resolution
const ensInput = document.getElementById('ensInput');
const ensSubmit = document.getElementById('ensSubmit');
const ensResult = document.getElementById('ensResult');

// Buttons that require connecting an account
const allConnectedButtons = [
deployButton,
Expand Down Expand Up @@ -457,6 +463,7 @@ const allConnectedButtons = [
maliciousPermitHexPaddedChain,
maliciousPermitIntAddress,
maliciousPermitIntAddress,
ensSubmit,
];

// Buttons that are available after initially connecting an account
Expand Down Expand Up @@ -509,6 +516,7 @@ const initialConnectedButtons = [
maliciousApproveERC20WithOddHexData,
maliciousPermitHexPaddedChain,
maliciousPermitIntAddress,
ensSubmit,
];

/**
Expand Down Expand Up @@ -3298,6 +3306,23 @@ const initializeFormElements = () => {
console.log(result);
};

/**
* ENS Resolution
*/
ensSubmit.onclick = async () => {
try {
ensResult.innerHTML = 'Resolving...';
const ensAddress = ensInput.value;
const ensResolver = await ethersProvider.getResolver(ensAddress);
const ethAddress = await ensResolver.getAddress();

ensResult.innerHTML = String(ethAddress);
} catch (error) {
console.error(error);
ensResult.innerHTML = 'Failed to resolve address';
}
};

/**
* Providers
*/
Expand Down

0 comments on commit 3216e2a

Please sign in to comment.