javascript - Node.js 如何获取类方法参数并使用它来调用“this.argument”
问题描述
嘿伙计们,我有一个问题。所以我在nodejs中有一个类,在构造函数中我初始化了一些来自uniswap的智能合约。但是,我正在制作一个函数,该函数将我在构造函数中初始化的智能合约作为参数。但是,当我尝试调用该方法并将 uniswapFactoryContract 作为名为“echangeName”的 arg 传递时,节点按原样采用 this.exchangeName,但我没有将 exchangeName 作为 arg 我传入它,而是将其作为 this.echangeName 而不是 this .TheNameOfTheArgIPassIn。我的代码在下面,任何人都可以帮助我或提供另一种方式
module.exports =class Registry {
constructor() {
//default token addresses
this.DAI = "0x6b175474e89094c44da98b954eedeac495271d0f";
this.WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
//default provided exhange addressses
this.UniswapFactoryAddress = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
this.UniswapRouterAddress = "0xf164fC0Ec4E93095b804a4795bBe1e041497b92a";
}
//when i call this in index.js i specifcy the uniswapFactoryaddress as the exchange name paramrer
async getTokenPairSddress(addressToken0, addressToken1, exchangeName) {
//this line throws the error it thinks i want this.echange name instead of
//this.uniswapFactoryContract
const pairAddress = await this.exchangeName.methods.getPair(addressToken0, addressToken1).call();
return pairAddress;
}
}
解决方案
推荐阅读
- elasticsearch - Elasticsearch 按任意顺序对术语 agg 进行排序
- python - 如何使用 Python 从 sqlite3 显示 BLOB 对象(图像)
- html - 红色背景的跨度不可见?
- java - ¿ 我可以在 Optapplaner 求解器配置中调整什么来选择这个动作?
- reactjs - 如何在 axios 中附加 JSON Web 令牌
- python - 如何从熊猫列表中获取价值?
- c++ - 将数据从 c++ 文件连续发送到 Python 脚本以进行进一步处理
- c++ - 如何使用多线程生成事件以及如何在 C++ 中同步它们?
- bootstrap-4 - 无法让引导网格与 shopify 购买按钮一起使用
- java - 如何将 Alfresco 查询结果集限制为仅前 N 行