首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >链接库在没有迁移的情况下收缩

链接库在没有迁移的情况下收缩
EN

Ethereum用户
提问于 2019-02-21 10:21:35
回答 1查看 83关注 0票数 0

要在迁移中链接库,我使用:

代码语言:javascript
运行
复制
await deployer.deploy(MyTokenL)
await deployer.link(MyTokenL, MyToken)

我们希望使用迁移作为基础设施部署,然后为使用基础设施的令牌提供部署工厂nodejs。我读到迁移对于这种工厂方法来说并不理想,因为迁移不打算多次部署相同的令牌。

因此,我有已部署的MyTokenL,并希望通过以下方式将其链接到部署的新契约,而无需迁移:

代码语言:javascript
运行
复制
//how link existing library, there is no deployer available???
const newlyDeployedToken = await MyToken.new()
EN

回答 1

Ethereum用户

发布于 2019-02-22 22:40:40

这是金子:

代码语言:javascript
运行
复制
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);
};

像这样使用它:

代码语言:javascript
运行
复制
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作为第一个参数加载,并执行同样的技巧.

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/67417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档