Devcon VI Workshop
Kudos to @Mrtenz for the Snap implementation.
Our goal is to create a snap that decodes contract call function names and parameters using the 4byte API and @metamask/abi-utils
.
Create a new GitHub repository using the template snap monorepo.
git clone
your new repository.yarn install
at the monorepo root.
yarn
installed, you can start the installation by directly running .yarn/releases/yarn-3.2.1.cjs install
from the monorepo root.Boot the snap and website by running yarn start
at the monorepo root.
Install the example snap by clicking Connect
on the website, then try out its functionality by clicking Send message
.
Rewrite the snap to use the transaction insights API.
snap.manifest.json
, replace the snap_confirm
permission with endowment:transaction-insight
.index.ts
, replace the onRpcRequest
handler with an onTransaction
handler. Make sure it is exported.@metamask/utils
as a dependency of your snap and import it in your snap's index.ts
file.Customize the website to suit your snap, and rewrite the Send message
logic to create an Ethereum transaction instead.
TransactionConstants
as the recipient address. See Transaction Snippets below.Click Reconnect
in the UI to reinstall the snap, then click Send message
to observe your "decoded transaction".
Call the 4byte API from within your snap.
endowment:network-access
to your snap's permissions.Finally, decode the parameters using @metamask/abi-utils
.
@metamask/abi-utils
as a dependency of your snap and import it in your snap's index.ts
file.normalizeAbiValue
function from the Value Normalizer Snippet and paste it into your snap's index.ts
file.@metamaks/abi-utils
, and return your your completed insights.We will demonstrate our snap's functionality by decoding some mock contract transactions that we create. You can of course try some contract interactions on your own as well.
We will use the 4byte API in our Snap. Here is a snippet with some constants: