要在迁移中链接库,我使用:
await deployer.deploy(MyTokenL)
await deployer.link(MyTokenL, MyToken)
我们希望使用迁移作为基础设施部署,然后为使用基础设施的令牌提供部署工厂nodejs。我读到迁移对于这种工厂方法来说并不理想,因为迁移不打算多次部署相同的令牌。
因此,我有已部署的MyTokenL,并希望通过以下方式将其链接到部署的新契约,而无需迁移:
//how link existing library, there is no deployer available???
const newlyDeployedToken = await MyToken.new()
发布于 2019-02-22 22:40:40
这是金子:
const linkContractWithLibrary = async (
ContractArtifact,
LibraryArtifact,
libraryAddress
) => {
const libraryName = LibraryArtifact.contractName;
const libraryInstance = await LibraryArtifact.at(libraryAddress);
//link function https://github.com/trufflesuite/truffle-contract/blob/develop/contract.js#L564
ContractArtifact.link(libraryName, libraryInstance.address);
console.log("=> Used lib " + libraryName + ":" + libraryInstance.address);
};
像这样使用它:
const MyToken = artifacts.require("MyToken.sol");
const MyTokenL = artifacts.require("MyTokenL.sol");
const myTokenLAddress = "0x4921e3822Ff02E0FbfEF1CB906b785484ccaf074";
//linking existing library
await linkContractWithLibrary(
MyToken,
MyTokenL,
myTokenLAddress
);
artifacts.require()也只能在测试中使用,但我想您可以将abi作为第一个参数加载,并执行同样的技巧.
https://ethereum.stackexchange.com/questions/67417
复制相似问题