Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
Background
ERC-5169 defines a way for clients to find executable scripts associated with a token's functionality.
This article translates, summarizes, and expands on the proposal below.
I cover other ERCs here as well.
Overview
The proposal lets clients discover scripts associated with an Ethereum smart contract. The scriptURI() function returns the URIs where clients can find scripts linked to the token.
A script here is a program or piece of code that works with a smart contract. It can be a client-side application or a set of instructions that helps users interact with a contract. Scripts can extend what users do with a token and carry out operations specific to that token.
Examples include:
- miniDapp
- A small decentralized application (DApp) dedicated to a particular token.
- It gives users access to features or information associated with that token.
- TokenScript
- A script that helps users operate a token or look up information about it.
- For example, it can surface token-specific information in a browser wallet or expose a contract function such as
mintthat the wallet does not ordinarily support.
- Smart lock controls
- JavaScript instructions that let a user operate a device such as a smart lock after receiving an authorization token.
These scripts make smart contract interactions more intuitive and efficient, especially for tokens such as ERC-20 and ERC-721.
Motivation
The proposal is useful to developers who want Ethereum tokens to offer features beyond standard wallet operations. NFTs are a common example. A contract needs a direct link to the client script that handles the token's specific behavior on the user's behalf.
With ERC-5169, a contract can advertise the URI of its official script. Clients use the URI to identify the intended script. Calling scriptURI can return a location on IPFS, GitHub, or cloud storage. A script found this way can provide client-side functionality such as:
- A small DApp dedicated to a single token (a
miniDapp). - A
TokenScriptthat provides information or hints in a browser wallet. - A
TokenScriptthat exposes functions such asmintthat an ordinary wallet does not expose. - An extension that can be downloaded to a hardware wallet such as a Ledger device.
- JavaScript instructions to operate a smart lock after the owner receives a particular token in their wallet.
This gives users a consistent way to find and use client scripts for working with their tokens securely and efficiently.
How script registration works
The contract manages links to client scripts, giving users a reference for identifying the intended script. The following terms describe the registration flow.
SCPrivKey
This is a private key used to administer the contract. Implementers can reuse a key that already manages the token. The authorized key is used to update the location recorded in scriptURI.
newScriptURI
This is the list of URIs where clients can find the script. Users can use these locations to retrieve the intended script.
The process has two main steps.
-
Issuance
- The token issuer deploys the contract and issues the token, then administers the contract with
SCPrivKey. - The issuer calls
setScriptURIto record the script locations inscriptURI.
- The token issuer deploys the contract and issues the token, then administers the contract with
-
Updating the script URI
- The issuer hosts the new script at one or more locations and prepares an updated list of URIs.
- The issuer calls
setScriptURIagain to update the contract.
With this setup, the issuer can manage script locations through the smart contract, and users have a contract-backed reference for finding the appropriate scripts. That enables richer functionality for ERC-20 and ERC-721 tokens.
Specification
interface IERC5169 {
/// @dev This event emits when the scriptURI is updated,
/// so wallets implementing this interface can update a cached script
event ScriptUpdate(string[] newScriptURI);
/// @notice Get the scriptURI for the contract
/// @return The scriptURI
function scriptURI() external view returns(string[] memory);
/// @notice Update the scriptURI
/// emits event ScriptUpdate(scriptURI memory newScriptURI);
function setScriptURI(string[] memory newScriptURI) external;
}IERC5169 defines how a smart contract reads and updates the list of locations for its client scripts.
ScriptUpdate
The contract emits this event when it changes scriptURI. Wallets and other clients can use it to update their cached script information.
scriptURI()
The function returns the contract's current list of script URIs. Clients use it to find the current script locations.
setScriptURI
The setter updates the stored URI list and emits ScriptUpdate with the new value.
Contracts implementing the interface must follow these rules:
- The contract stores its owner's address in an
address ownervariable. - The constructor sets the initial owner to the deployer (
msg.sender). - Updating
scriptURIthroughsetScriptURIemitsScriptUpdate. - Before executing
setScriptURI, the contract verifies that the caller is the owner (owner == msg.sender). - Before using a script from
scriptURI, the client must confirm that its location is immutable, its URI contains a content digest, or its authenticity is guaranteed through another EIP.
These controls let the contract manage script locations and updates while giving users a way to verify scripts used with tokens such as ERC-20 and ERC-721.
Hosting options
The scheme allows developers to host scripts somewhere other than a dedicated, security-hardened central server. Possible locations include IPFS, a distributed file system, GitHub, a code hosting service, or cloud storage. Developers can distribute scripts without depending on a single server. That makes scripts for ERC-20 and ERC-721 contracts easier to make available and gives clients more ways to access and use them.
Backward Compatibility
The standard works with most existing token standards, including:
- ERC-20
- ERC-721
- ERC-777
- ERC-1155
For more on ERC-20, see the following article.
For more on ERC-721, see the following article.
For more on ERC-777, see the following article.
[ERC-777] A guide to the standard token contract interface
For more on ERC-1155, see the following article.
Tests
The following example shows how a contract stores and manages the client script URI list and how a test checks that behavior.
Test contract
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IERC5169.sol";
contract ERC5169 is IERC5169, Ownable {
string[] private _scriptURI;
function scriptURI() external view override returns(string[] memory) {
return _scriptURI;
}
function setScriptURI(string[] memory newScriptURI) external onlyOwner override {
_scriptURI = newScriptURI;
emit ScriptUpdate(newScriptURI);
}
}ERC5169manages URIs for client scripts.- It implements
IERC5169and usesOwnableto restrict privileged operations to the owner.
- It implements
- The
_scriptURIvariable holds the list of URIs where clients can find scripts. scriptURI()returns the current list.setScriptURI()replaces the list and emitsScriptUpdate.- Only the owner can call the setter.
Test case
const { expect } = require('chai');
const { BigNumber, Wallet } = require('ethers');
const { ethers, network, getChainId } = require('hardhat');
describe('ERC5169', function () {
before(async function () {
this.ERC5169 = await ethers.getContractFactory('ERC5169');
});
beforeEach(async function () {
// targetNFT
this.erc5169 = await this.ERC5169.deploy();
});
it('Should set script URI', async function () {
const scriptURI = [
'uri1', 'uri2', 'uri3'
];
await expect(this.erc5169.setScriptURI(scriptURI))
.emit(this.erc5169, 'ScriptUpdate')
.withArgs(scriptURI);
const currentScriptURI = await this.erc5169.scriptURI();
expect(currentScriptURI.toString()).to.be.equal(scriptURI.toString());
});- The test deploys an
ERC5169contract and writes a list of three sample URIs ('uri1', 'uri2', 'uri3') to check that the contract updates the list correctly. - After calling
setScriptURI(), the test checks forScriptUpdateand reads the stored list throughscriptURI()to confirm that it matches the input.
These checks cover both the update notification and the persisted state.
Reference Implementation
Smart Token Labs (STL) developed an office door token that uses an NFT to give employees access to its unlocking system. Employees receive an NFT associated with instructions for the door's interface. The token contract exposes those instructions as a TokenScript through scriptURI().
The process works as follows.
- The client asks the IoT device for a random challenge string, such as 'Apples-5E3FA1'.
- The challenge acts much like a temporary password for opening the door.
- The client displays the string in the token view and prompts the user to choose Sign Personal.
- This action asks the user to sign the challenge string.
- The client sends the signed challenge back to the IoT device.
- The device unlocks the door after verifying that the signature comes from an address that holds the NFT.
Since the client can discover the instructions through scriptURI(), users can operate the door as soon as they receive the NFT. This reduces the work needed to start using it.
The system is used for installations beyond Smart Token Labs' office door. See the ERC-5169 example contract and ERC-5169 TokenScript example for details. The associated discussion includes links to the firmware and full sample. A client retrieves the TokenScript location by calling scriptURI() on the contract.
Script locations
Storing NFT scripts directly in a smart contract is straightforward but has drawbacks. Updating a script requires a signing key, and frequent use of the key increases security exposure. Frequent writes increase transaction costs, and large scripts are expensive to store on-chain.
The proposal recommends using external resources to host token scripts. Options include centralized cloud hosting, a privately operated server, and a distributed system such as IPFS.
Centralized storage may conflict with Web3's preference for decentralization, while a fully decentralized approach can have speed, cost, or storage constraints. The scriptURI() function can return several URIs, including a mix of centralized, privately hosted, and distributed locations.
The proposal leaves the script format open. A script can link to other scripts or data sources, making it possible to load resources on demand. The integrity of secondary resources depends on the script format, so developers need to account for it.
Security Considerations
When a server is involved
A client script may call a server API in addition to querying blockchain nodes. ERC-5169 does not authenticate API endpoints. A script that has been verified can call an API to implement token functionality, but that does not establish the trustworthiness of the API.
When scriptURI does not contain integrity information
If the script URI does not identify the content by its hash, the client needs another way to verify authenticity and integrity. The article points to a separate proposal on client script authenticity that uses digital signatures for this purpose.
Clients need to establish trust in both scripts and the server APIs they use. The script location and format can affect which additional safeguards are necessary.
Citation
James (@JamesSmartCell), Weiwu (@weiwu-zhang), "ERC-5169: Client Script URI for Token Contracts," Ethereum Improvement Proposals, no. 5169, May 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5169.
Conclusion
ERC-5169 gives token contracts a standard way to point clients to executable scripts related to token functionality.
If you have questions, feel free to send me a direct message.
I publish in other places as well.


