Skip to content

PhantomOz/foundry-yul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foundry Yul Deployer

A Foundry library for deploying smart contracts written in Yul.

Installation

Install the library using forge:

forge install foundry-yul/foundry-yul

Then, add the library to your remappings.txt:

foundry-yul/=lib/foundry-yul/

Usage

This library provides a YulDeployer library that can be used in your deployment scripts.

1. Write your Yul contract

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.

2. Compile your project

Build your project, which will compile your Yul contract:

forge build

This will create an artifact at out/MyToken.json.

3. Write a deployment script

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();
    }
}

4. Deploy

Run your deployment script:

forge script script/Deploy.s.sol:DeployMyTokenScript --rpc-url <your_rpc_url> --broadcast

Examples

This 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published