ประเภทหนัง
ตัวอย่างหนัง Metamask: Getting execution reverted: ERC20: transfer amount exceeds allowance code: UNPREDICTABLE_GAS_LIMIT method
** Metamka:
As a developer that is decentered application (DAPPs) through smart contracts, you’re probably familiar with the imports of secure and reliable communications your application and extlic services. Howver, Sometimes Unexpected Problems can occurely in the external swaps, causing to be restored.
This article, we will go in the so-care instructions and give instructions.
ERC20 transfer amunt exceeding the benefit
There will be a step-in trouble hooting is to understand the cause off them. The report “Updded Execution: ERC20: The Transfer Amount Exceeds the The Premium the The The The The The The The The The The The The External Switch Function has rejected your request to the insect benefit. This can have a when:
- The recipient’s purse does not ot enugh ether (ETH).
- There’s a transaction amont is high that recipient can afford.
- There are the “marker property” or the “Transfer” function.
Metamak: Repeat Fulfillment
To-restore execution and soles, you will be logic off the logic case case transfer aunt exceeds the benefits. One approach is to ocese the bilt -in soup-instances will be used for retrictions in swap functions.
Here’s an example off how of you can change your contract:
`TypesCript
Import {ethers} from “ethers”;
Const Max_transfer_amont = 10000000; // Eth
Export the exchange off async functions (amont: number) {
Const Benefit = Expect Agreement Benefits.Call ();
if (benefit.value
Console.log (‘Execution of insufficient benefit associated with ethforce:’, amunt);
return;
}
CONST GAMLIMIT = Expects.
If (Gaslimit.value <= 20000) {// Complicated gas border coding
Throw a new mistake (‘gas retrict is too low’);
}
Try
Const tx = wait for contract.Swap (amunt, benefit.value – amunt);
Console.log (‘Swap Transaction Successful executed:’, tx.hash);
// … The rest of your swap function code …
} Catch (error) {
IF (Ethers.Agredror || Error Error.Stus == 0x800000) {// Execion Restoreed
Console.log ( ‘Execution was restored due to their limit:’, earror.message);
throw a mistake;
}
}
}
Export async feature MAIN () {
wait for the tract.Delther ();
}
`
This is what you’re doing to the elections.
Hard configuration
You will have a following TypesCript Code Fragment to Enables Restruation Subport in your hardness Configuration:
`TypesCript
Import {hardhadruntimevironment} from “Hardhat-TypesCript”;
Import {web3provider} freelance ‘@member/web3 provider’;
The default function configuration ({network}) {
taxi {
// … receive contact settings
Gaslimits: 20000, // Gas limit for swap
};
}
`
Conclusion
Conditioning the errors of the “execution” of the basic and introduction that is the premium transfers. and reliable interaction between your application and external service. for testing and debugging to prevent problems.
If you have a constant mistakes or need addion, consider contact the the Ethereum Community or Seeking Instructions on Experienced Developers is your network.