ERC-7738 Script Registry Contracts, deployment and test harness scripts
ERC-7738 Script Registry Contracts, deployment and test harness scripts
This folder contains sample (and actual deployed) ERC-7738 registry contracts and tapp scripts
Test suite
- Init hardhat in this directory
npm install --save-dev hardhat
- Run the test harness
npx hardhat test
Test a script on the registry
Deploy Example Token
Deploy a test token, let’s use a simple ERC-721 with a custom mint function:
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC721, Ownable {
uint256 private _tokenId;
constructor()
ERC721("MyToken", "MTK")
Ownable(msg.sender)
{
_tokenId = 1;
}
function mint() public {
_safeMint(msg.sender, _tokenId);
_tokenId++;
}
}
Deploy this NFT using eg Remix and make a note of the contract address.
Create Simple TokenScript, emulate and Deploy
First install the TokenScript CLI tool
- Install the TokenScript build tool (see TokenScript Quickstart)
npm install -g @tokenscript/cli
Here is a minimal example minting tokenscript object file: Basic NFT TokenScript.
- Copy or clone this code to a directory, ensure it is called tokenscript.xml.
- Locate the following line in the TokenScript: ```xml
Replace the ChainId and CONTRACT_ADDRESS with the contract you deployed in the previous step.
4. Use Emulation to test (in the same directory as you put the examples/tokenscript.xml file):
```bash
tokenscript emulate
This will let you test the TokenScript functionality before deploying on the registry. The generated page will allow you to mint new tokens.
- Upload the TokenScript to an FTP or IPFS and make a note of the URL or IPFS hash.
Add script to the registry
- Open the registry page: Holesky Registry Page Sepolia Registry Page Base Sepolia Registry Page
Click on the onboarding button “Set ScriptURI”. Set the contract address and scriptURI in the card.
- Test onboarding. Switch wallets, go to the token page of your token (eg for Holesky):
https://viewer-staging.tokenscript.org/?chain=17000&contract=<YOUR CONTRACT ADDRESS>
This will open the TokenScript for your deployed contract. Click on the Mint onboarding button to generate new Tokens.
Deploy your own registry on a testnet
For this test we will use Holesky, but you can also use Sepolia, or any testnet on which the ENS contracts has been deployed.
Add some test eth on 2 wallets (0.1 -> 0.5 depending on gas price on the testnet) Create a .env file which contains the following three keys:
PRIVATE_KEY_DEPLOY = "0x<PRIVATE KEY 1>"
PRIVATE_KEY_2DEPLOY = "0x<PRIVATE KEY 2>"
PRIVATE_KEY_ENS = "0x<PRIVATE KEY ENS>"
Create an ENS domain on Holesky using the PRIVATE_KEY_ENS wallet. Obtain a .eth
domain, not .box
or any other. Go to the ENS app https://app.ens.domains/ and obtain a new ENS using your Holesky.
Using the app, unwrap the domain. Click on “More” then “Unwrap”.
Now, use the script to transfer ownership of the ENS to where the ENSAssigner contract will be written:
- Add the ENS name to your .env file (don’t add the .eth suffix).
ENS_NAME="<YOUR ENS>"
eg, if the domain you picked was “kilkennycat.eth”:
ENS_NAME="kilkennycat"
- Run the script (note this script changes ownership of the domain to the ENSAssigner contract that will soon be deployed)
npx hardhat run ./scripts/changeENSOwner.ts --network holesky
Now, ensure the change ownership transaction is written (check the console log of first deployment), and run the deploy script:
npx hardhat run ./scripts/deploy.ts --network holesky
Congrats your registry is deployed. Now to issue a bootstrap script for the registry.
Generate TokenScript and upload to IPFS
- Open the
./tokenscript
folder in your favourite editor, and find thetokenscript.xml
file. - Locate the Origin contract definition line: ```xml