【问题标题】:'ERC20: insufficient allowance' when staking\'ERC20: 质押时津贴不足\'
【发布时间】:2023-01-18 10:28:11
【问题描述】:
部署了一个 ERC20,它被设置为单独的 staking 合约(保险库)的资产。
我能够在 ERC20 中铸造、转移和增加津贴,但在尝试使用“抵押/存款”功能时——返回:
Error: VM Exception while processing transaction: reverted with reason string 'ERC20: insufficient allowance'
地址设置为 spender + owner,链上调用验证了 spender 在 ERC20 下的批准。
有任何想法吗?我怀疑它与代理/合同路由有关。
尝试将 ERC20 质押到质押合约中,收到“配额不足”错误。
【问题讨论】:
标签:
solidity
ethers.js
erc20
【解决方案1】:
你有没有调用你的 ERC20 合约上的 approve 函数来批准质押合约?
如果你这样做了,请尝试再次检查你对质押合约的配额是否高于你想要质押的金额。如果质押合约的津贴为 0,那么它将失败,因为你基本上没有从质押合约中获得任何许可,以将你的 ERC20 代币用于质押。
要检查您的质押合约的代币配额,您可以使用 Moralis
import Moralis from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';
try {
const chain = EvmChain.ETHEREUM;
const address = '';
const ownerAddress = '';
const spenderAddress = ''
await Moralis.start({
apiKey: 'YOUR_API_KEY',
// ...and any other configuration
});
const response = await Moralis.EvmApi.token.getTokenAllowance({
address,
chain,
});
console.log(response?.result);
} catch (e) {
console.error(e);
}
其中参数是:
-
address 是您的 ERC20 代币地址
-
chain 是你的 ERC20 令牌链
-
ownerAddress 是想要质押 ERC20 代币的地址
-
spenderAddress 是质押合约
您可以按照本教程进一步了解更多详细信息https://docs.moralis.io/web3-data-api/evm/how-to-get-the-spender-allowance
希望这可以帮助!