I'm trying to call a function named "remove_liquidity_one_coin" from a smartcontract on FTM network, but I get following error and cannot figure out why:
TypeError: curveContract.remove_liquidity_one_coin is not a function
Usually, when I want to call functions of a contract, I take the ABI, the contract address, then I instantiate it and I can use its functions.
For the contract below, It works well for "read" functions, but not "write" functions like remove_liquidity_one_coin
.
Here is the simplified code I use:
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(
liquidityToRemove, // Amount to withdraw
0, // Index of the token to receive
expectedAmount // Expected amount to withdraw
);
Do you know what I am missing?
Edit I ended by using only the Abi of the functions I want. Example:
let signer = new ethers.Wallet(privateKey, provider)
let contractAddress = "0xa58f16498c288c357e28ee899873ff2b55d7c437"
let functionAbi = ["function remove_liquidity_one_coin(uint256 burn_amount, int128 i, uint256 min_received) public returns (uint256)"];
let curveContract = new ethers.Contract(contractAddress, functionAbi, signer)
// Write function => works
let receivedCoins = await curveContract.remove_liquidity_one_coin(
liquidityToRemove, // Amount to withdraw
0, // Index of the token to receive
expectedAmount // Expected amount to withdraw
);
See this GitHub discussion answer by ricmoo:
I am assuming you mean the method
buy
?You have multiple definitions of
buy
in your ABI, so you need to specify which you mean. I highly recommend you trim down your ABI to just include the methods you use, but if you wish to keep the full ABI, you will need to use:// There are two "buy" methers, so you must specify which you mean: // - buy(uint256) // - buy(uint256,bytes) contract["buy(uint256)"](shareId, overrides)
If you trim down the ABI to exclude the ones you don't use, you will be able to have cleaner code (the code you have already would work) and you would cut about 2 megabytes off your application size, as most of that (massive) ABI is unused.
In short, if there are several methods with the same name but different signatures, this error occurs.