Skip to main content

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

  1. Initialize a new project using forge init and cd into it
forge init hello_world
cd hello_world
  1. Install enscribe from Github repository using forge install
forge install enscribexyz/enscribe
  1. Install openzeppelin from Github repository using forge install
forge install OpenZeppelin/openzeppelin-contracts
  1. Create remapping.txt and add the following to it to simplify imports:
enscribe/=lib/enscribe/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
  1. Make Counter implement Ownable from OpenZeppelin and call the Ownable constructor with the sender's address
import "@openzeppelin/contracts/access/Ownable.sol";
contract Counter is Ownable {
constructor(uint256 initialCount) Ownable(msg.sender) {
number = initialCount
}
}
  1. Set a primary name for the contract address in Counter.s.sol using the enscribe library
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();
}
}
  1. 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: