From d611ae2fd267e98071fc539984f34f9676237aba Mon Sep 17 00:00:00 2001 From: PeterYinusa Date: Tue, 7 Nov 2023 16:11:21 +0000 Subject: [PATCH] wallet_watchAsset for ERC1155 --- src/index.html | 20 ++++++++++++++++++++ src/index.js | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/index.html b/src/index.html index a72d9865..b87216e4 100644 --- a/src/index.html +++ b/src/index.html @@ -602,6 +602,26 @@

+
+ + +
+ +
+ +
+

ERC 1155:

diff --git a/src/index.js b/src/index.js index f4eb9d13..016f6aff 100644 --- a/src/index.js +++ b/src/index.js @@ -123,6 +123,8 @@ const setApprovalForAllERC1155Button = document.getElementById( 'setApprovalForAllERC1155Button', ); const revokeERC1155Button = document.getElementById('revokeERC1155Button'); +const watchAssetInput = document.getElementById('watchAssetInput'); +const watchAssetButton = document.getElementById('watchAssetButton'); const erc1155Status = document.getElementById('erc1155Status'); // ERC 747 Section @@ -264,6 +266,8 @@ const allConnectedButtons = [ batchTransferFromButton, setApprovalForAllERC1155Button, revokeERC1155Button, + watchAssetInput, + watchAssetButton, deployFailingButton, sendFailingButton, deployMultisigButton, @@ -802,6 +806,8 @@ const updateContractElements = () => { batchTransferFromButton.disabled = false; setApprovalForAllERC1155Button.disabled = false; revokeERC1155Button.disabled = false; + watchAssetInput.disabled = false; + watchAssetButton.disabled = false; // ERC20 Token - Send Tokens tokenAddresses.innerHTML = hstContract ? hstContract.address : ''; watchAssets.disabled = false; @@ -1142,6 +1148,8 @@ const initializeFormElements = () => { batchTransferFromButton.disabled = false; setApprovalForAllERC1155Button.disabled = false; revokeERC1155Button.disabled = false; + watchAssetInput.disabled = false; + watchAssetButton.disabled = false; }; batchMintButton.onclick = async () => { @@ -1218,6 +1226,24 @@ const initializeFormElements = () => { erc1155Status.innerHTML = 'Revoke completed'; }; + watchAssetButton.onclick = async () => { + try { + const watchAssetResult = await ethereum.request({ + method: 'wallet_watchAsset', + params: { + type: 'ERC1155', + options: { + address: erc1155Contract.address, + tokenId: watchAssetInput.value, + }, + }, + }); + console.log(watchAssetResult); + } catch (error) { + console.error(error); + } + }; + /** * EIP 747 */