ERC-5169 · Final · ERC · 2022-05-03
ERC-5169: Client Script URI for Token Contracts
Lets a token contract publish, via scriptURI(), where to fetch its official client-side script, so wallets can load trusted token-specific functionality straight from the contract.
What problem does it solve?
Many tokens do more than sit in a wallet: an NFT might open an office door, a ticket might need check-in, a contract might have a mint function that wallets don't show. Projects deliver this through client scripts or mini dApps. The question is how a wallet or user knows which script is the official one for a token, since a fake script could build malicious transactions.
ERC-5169 anchors the answer in the token contract itself: call scriptURI() and you get the locations of the script the contract's owner endorses.
How it works
interface IERC5169 {
event ScriptUpdate(string[] newScriptURI);
function scriptURI() external view returns (string[] memory);
function setScriptURI(string[] memory newScriptURI) external;
}
scriptURI()returns an array of URIs (any RFC 3986 URI: IPFS, a GitHub gist, cloud storage…), so the same script can be mirrored across centralised and decentralised hosts.- The contract keeps an
owner, set to the deployer; only that owner may callsetScriptURI. - Every update emits
ScriptUpdate, so wallets can refresh a cached script. - The format of the script is not fixed. Examples include a "TokenScript", a cut-down single-token dApp, or a hardware-wallet extension.
- Integrity is the client's job: anyone using the script must check it is at an immutable location, that the URI contains the script's hash, or that it carries a signature per the authors' companion "Authenticity for Client Script" proposal.
Storing the script off-chain avoids heavy storage fees and avoids frequent use of the admin key for every script tweak.
Sample code
Contract side (OpenZeppelin v5 Ownable):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
interface IERC5169 {
event ScriptUpdate(string[] newScriptURI);
function scriptURI() external view returns (string[] memory);
function setScriptURI(string[] memory newScriptURI) external;
}
contract ScriptedToken is IERC5169, Ownable {
string[] private _scriptURI;
constructor() Ownable(msg.sender) {}
function scriptURI() external view returns (string[] memory) {
return _scriptURI;
}
function setScriptURI(string[] memory newScriptURI) external onlyOwner {
_scriptURI = newScriptURI;
emit ScriptUpdate(newScriptURI);
}
}
Wallet side (ethers v6), reading the list before fetching and verifying a script:
import { Contract } from "ethers";
const token = new Contract(tokenAddress,
["function scriptURI() view returns (string[])"], provider);
const uris: string[] = await token.scriptURI();
// e.g. ["ipfs://<cid>", "https://example.com/token.tsml"]
// Prefer content-addressed URIs; otherwise verify a hash or signature before running.
Things to know
- Status: Final.
scriptURItells you what the contract owner endorses, not that the script is safe. A compromised owner key can point every wallet at a malicious script, so treat updates with the same care as a contract upgrade.- An
https://URI alone gives no integrity guarantee; content-addressed storage (IPFS CID) or a signature check is needed before executing anything. - If the script calls external server APIs, this standard says nothing about trusting those servers.
- It works alongside ERC-20, ERC-721, ERC-777 and ERC-1155 tokens without changing their behaviour.