我试图从 FTM 网络上的智能合约调用名为“remove_liquidity_one_coin”的函数,但出现以下错误并且无法找出原因:
TypeError: curveContract.remove_liquidity_one_coin is not a function
通常,当我想要调用合约的函数时,我会获取 ABI(合约地址),然后实例化它并可以使用它的函数。
对于下面的合约,它适用于“读取”功能,但不适用于“写入”功能,例如remove_liquidity_one_coin.
这是我使用的简化代码:
let signer = new ethers.Wallet(privateKey, provider)
let contractAddress = "0xa58f16498c288c357e28ee899873ff2b55d7c437"
let contractAbi = [...] // ABI of the contract. In this case: https://api.ftmscan.com/api?module=contract&action=getabi&address=0x3cabd83bca606768939b843f91df8f4963dbc079&format=raw
let curveContract = new ethers.Contract(contractAddress, contractAbi, signer)
// Read function => works
let liquidityToRemove = await curveContract.calc_withdraw_one_coin(
lpTokenToWidraw, // Amount to withdraw
0 // Index of the token to withdraw
);
// Write function => doesn't work
let receivedCoins = await curveContract.remove_liquidity_one_coin( …Run Code Online (Sandbox Code Playgroud)