A Foundry library for deploying smart contracts written in Yul.
Install the library using forge:
forge install foundry-yul/foundry-yulThen, add the library to your remappings.txt:
foundry-yul/=lib/foundry-yul/
This library provides a YulDeployer library that can be used in your deployment scripts.
Place your Yul contract in your project's src directory (or wherever you keep your sources). For example, src/MyToken.yul:
object "MyToken" {
code {
datacopy(0, dataoffset("runtime"), datasize("runtime"))
return(0, datasize("runtime"))
}
object "runtime" {
code {
// Your contract's runtime logic
}
}
}The name of the object ("MyToken" in this case) is important, as it's used to find the compilation artifact.
Build your project, which will compile your Yul contract:
forge buildThis will create an artifact at out/MyToken.json.
Create a deployment script that imports and uses YulDeployer.
script/Deploy.s.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import "forge-std/console.sol";
import "foundry-yul/src/YulDeployer.sol";
contract DeployMyTokenScript is Script {
function run() public {
vm.startBroadcast();
// The first argument to `deploy` is the vm, the second is the Yul contract object name
address token = YulDeployer.deploy(vm, "MyToken");
console.log("MyToken deployed to:", token);
vm.stopBroadcast();
}
}
Run your deployment script:
forge script script/Deploy.s.sol:DeployMyTokenScript --rpc-url <your_rpc_url> --broadcastThis repository contains an example Yul contract and deployment script.
This project is based on the idea of making Yul development more accessible within the Foundry ecosystem.