Assets
Simple Summary
An RPC method for allowing users to easily track new assets with a suggestion from sites they are visiting.
Web3 JavaScript wallet browsers may implement the wallet_watchAsset
RPC method to allow any website to suggest a token for the user’s wallet to track.
Today, one of the major uses of blockchain wallets is to acquire and track assets. Currently, each wallet either needs to pre-load a list of approved assets, or users need to be stepped through a tedious process of adding an asset for their given wallet.
In the first case, wallets are burdened with both the security of managing this list, as well as the bandwidth of mass polling for known assets on their wallet.
In the second case, the user experience is terrible.
By leveraging a user’s existing trust with websites they are learning about assets on, we are able to decentralize the responsibility of managing a user’s list of known assets.
Jetton Example
The example is the button with a show and allows to save Wrapped SOL coin from tonswap.org project in your OpenMask.
export default () => {
const addWSOL = async () => {
const provider = window.ton;
try {
await provider.send("wallet_watchAsset", {
type: "jetton",
address: "EQC4cCygTZPKIP9cCsWx7DW5i5MQPOsEcfKkKwBZKkRCCfaW",
});
} catch (e) {
console.error(e);
}
};
return (
<div>
<button onClick={addWSOL}>Watch Wrapped SOL Coin</button>
</div>
);
};
NFT Example
The example is the button with a show and allows to save TON Smart Challenge #2 Winners Trophy NFT. For the example the Add NFT button will disabled, because it's another NFT.
export default () => {
const addNFT = async () => {
const provider = window.ton;
try {
await provider.send("wallet_watchAsset", {
type: "nft",
address: "EQD197AvD5v-9Klyp2VATZtjJDUoW8hPL4yDU4ijopBjpLoG",
});
} catch (e) {
console.error(e);
}
};
return (
<div className="py-8">
<button
onClick={addNFT}
className="py-3 px-5 mb-3 bg-[#88d3ff] text-black text-lg"
>
Watch NFT Mainnet Asset
</button>
</div>
);
};