1.10.0 • Published 7 months ago
@ututrust/utu-metamask-snap v1.10.0
UTU Trust Metamask Snap
UTU has built a Snap (basically a MetaMask plugin) to let you get UTU signal inside your MetaMask Wallet right at the moment when you're about to confirm a transaction.
At the moment the UTU Snap is only available in MetaMask Flask (an experimental version of MetaMask) that you can think of like a training ground for the big stage.
UTU Trust SDK provides web-components that access UTU’s Trust API and allows you simple integration with its services.
Find the repository here
Install
$ npm i @ututrust/utu-metamask-snap
Example
Quickstart React
import React from 'react';
const Snap = () => {
const getEnv = () => {
let env = 'staging';
if (window.location.href.includes('3000')) {
env = 'local';
} else if (process.env.REACT_APP_API_URL?.includes("<place-your-production-api-url>")) {
env = 'production';
}
return env;
};
const installMetaMaskFlask = () => {
const win = window.open('https://metamask.io/flask/', '_blank');
win.focus();
};
const installSnap = async () => {
try {
const accessToken = await getUTUApiAccessToken(); // Replace with your logic for fetching the token
// Request to add the UTU Snap
await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
'npm:@ututrust/utu-metamask-snap': {},
},
});
const env = getEnv();
// Authorize the UTU Snap
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@ututrust/utu-metamask-snap',
request: {
method: 'authorizeUTUSnap',
params: { token: accessToken, env },
},
},
});
console.log("UTU Snap installed and authorized!");
} catch (error) {
console.error("Error installing or authorizing the UTU Snap:", error);
}
};
return (
<div>
<button onClick={installMetaMaskFlask}>
Install MetaMask Flask
</button>
<button onClick={installSnap}>
Install UTU Snap into MetaMask Flask
</button>
</div>
);
};
export default Snap;