Foundry Library
Foundry Solidity library that works with Foundry scripts to enable contract naming at deployment time.
Installation
forge install enscribexyz/enscribe
High-level API
function setName(
uint256 chainId,
address contractAddress,
string memory fullName
) internal returns (bool success)
Sets both forward and reverse resolution for a contract address. This is the main function you'll use in most cases.
Example
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {Ens} from "enscribe/Ens.sol";
contract CounterScript is Script {
function run() public {
vm.startBroadcast();
counter = new Counter();
Ens.setName(block.chainid, address(counter), "mycontract.mydomain.eth");
vm.stopBroadcast();
}
}
function setName(
uint256 chainId,
address contractAddress,
string memory fullName
) internal returns (bool success)
Sets only forward resolution (name → address) without setting reverse resolution. Useful when you only need forward lookup.
Example
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {Ens} from "enscribe/Ens.sol";
contract CounterScript is Script {
function run() public {
vm.startBroadcast();
counter = new Counter();
Ens.setForwardResolution(block.chainid, address(counter), "mycontract.mydomain.eth");
vm.stopBroadcast();
}
}
An end-to-end example of using Enscribe with Foundry
- Initialize a new project using
forge initand cd into it
forge init hello_world
cd hello_world
- Install
enscribefrom Github repository usingforge install
forge install enscribexyz/enscribe
- Install
openzeppelinfrom Github repository usingforge install
forge install OpenZeppelin/openzeppelin-contracts
- Create
remapping.txtand add the following to it to simplify imports:
enscribe/=lib/enscribe/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
- Make
CounterimplementOwnablefrom OpenZeppelin and call theOwnableconstructor with the sender's address
import "@openzeppelin/contracts/access/Ownable.sol";
contract Counter is Ownable {
constructor(uint256 initialCount) Ownable(msg.sender) {
number = initialCount
}
}
- Set a primary name for the contract address in
Counter.s.solusing theenscribelibrary
import {Ens} from "enscribesol/Ens.sol";
contract CounterScript is Script {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
counter = new Counter(0);
Ens.setName(block.chainid, address(counter), "enscribesol124.abhi.eth");
vm.stopBroadcast();
}
}
- Run the script
forge script script/Counter.s.sol:CounterScript --chain-id 11155111 --rpc-url $SEPOLIA_RPC_URL --broadcast --private-key $PRIVATE_KEY
You can now view the deployed contract in Enscribe app
Here's a visual tutorial of the above steps: