foundry-rs / book

A book on all things Foundry, available at https://book.getfoundry.sh.
https://book.getfoundry.sh
Apache License 2.0
826 stars 661 forks source link

Improve `--libraries` documentation for linking more than one library #673

Open yv-was-taken opened 2 years ago

yv-was-taken commented 2 years ago

forge create --libraries tag on contract deployment throws error when linking multiple libraries.

Not sure if lacking proper documentation showing the proper approach, or just a bug. Either way, as a user, I am confused as to how to link more than one external library on contract deployment.

ex.

forge create ExampleContract --rpc-url $RPC --private-key $KEY --libraries lib/solmate/src/utils/SafeCastLib.sol:SafeCastLib:0xaBcd0C11d7c8AaABBa176Cb5ab9531BCcF7711f1 
lib/solmate/src/utils/SafeTransferLib.sol:SafeTransferLib:0xabCd5E5C3C6d9fcb3150BF64015186f45C8F4273 lib/solmate/src/utils/FixedPointMathLib.sol:FixedPointMathLib:0xABCd3390ea4Ea050E296e1Eeb766193c8C0cb6c6

error: Found argument 'src/utils/SafeTransferLib.sol:SafeTransferLib:0xabCd5E5C3C6d9fcb3150BF64015186f45C8F4273' which wasn't expected, or isn't valid in this context

current docs:

--libraries libraries
    Set pre-linked libraries.

    The parameter must be in the format <remapped path to lib>:<library name>:<address>, e.g. src/Contract.sol:Library:0x....

    Can also be set in your configuration file as libraries = ["<path>:<lib name>:<address>"].
JuanXavier commented 11 months ago

I was having the same conundrum. If its helps anyone out there, just add the --libraries flag for each library, eg:

forge create ExampleContract --rpc-url $RPC --private-key $KEY \
--libraries lib/solmate/src/utils/SafeCastLib.sol:SafeCastLib:0x......\
--libraries lib/solmate/src/utils/SafeTransferLib.sol:SafeTransferLib:0x......\
--libraries lib/solmate/src/utils/FixedPointMathLib.sol:FixedPointMathLib:0x......