Ethereum Transaction Revertipstraverror: The transaction has been reversed by EVM
I have a found an error when trying to adliquent Winiswap V2 in Seolia Testnet use web3.js intrufle. The error is caused by a transaction that is reversed by Etherum virtual machine (EVM). Here is a detained explanation of the problem and possible solutions.
The problem:
When trying to execute Addliquidity
in the UNISWAP V2 interface, the EVM reverses the transaction. This can happen due to several reasons souch as:
- Insufficient liquidity in the pool.
- Balances or incorrect Token addresses.
- External calls not validated (for example, calls to external contraction).
- Incorrect gas limits.
The Code:
Here is a sample triffle contraction and web code fragment that reproduces the problem:
`JavaScript
// Seolia-truffle-contracts.js
const web3 = require ('web3');
Const trufa = require ('truffle');
const web3 = new web3 (new web3.providers.httPProvider ("
module.exports = {
Suppliers: [] //
Networks: {
development: {
Host: 'localhost',
Port: 8545,
Gas: 20000000
},
SEOLIA: {Network_id: 1}
},
Contracts: {
ADDLIQUIDITY: REQUIRE ('./ Addliquide.json')
}
};
JavaScript
balances: $ {balance}
// Addliquidity.js
const web3 = require ('web3');
const contract = new web3.et.contrate (require.Resolve ('/ Addliquidity'), '0x ...');
Contraction.metds.addliquet (address, quaantity, quaantity, price) .send ({from: '0x ...', value: '0.1'})
.Then ((result) => {
Console.log (result.status);
if (result.status === 'sugar') {
Contract.functions.getbalance.cal (address)
.Then ((balance) => {
Console.log (
);
});
} ones {
bar a new error ('error');
}
})
.Catch ((error) => {
Console.error (error);
Throwing error;
});
Potential solutions:
To solve that problem, make of the express:
- Specify a supplier : Add a matrix of
suppliers' with the EVM supplier (for example,
https: //pi.seolia.io.) in trufguration.
`JavaScript
// Seolia-truffle-contracts.js
const web3 = require ('web3');
Const trufa = require ('truffle');
const web3 = new web3 (new web3.providers.httPProvider ("
module.exports = {
Suppliers: []
Networks: {
development: {
Host: 'localhost',
Port: 8545,
Gas: 20000000
},
SEOLIA: {Network_id: 1}
},
Contracts: {
ADDLIQUIDITY: REQUIRE ('./ Addliquide.json')
}
};
externalcalalcala'
Validate exernal calls
: Make sor the
`
JavaScript
// Addliquidity.js
const web3 = require ('web3');
const contract = new web3.et.contrate (require.Resolve ('/ Addliquidity'), '0x ...');
Contractor.metds.addliquent (address, quaantity, quaantity, price)
.Call ({from: '0x ...'})
.Then ((result) => {
Console.log (result.status);
if (result.status === 'sugar') {
Contract.functions.getbalance.cal (address)
.Then ((balance) => {
Console.log (balances: $ {balance}
);
});
} ones {
bar a new error ('error');
}
})
.Catch ((error) => {
Console.error (error);
Throwing error;
});
- Encourage the Gas limits : Establish iti gs to limits to the prevent the EVM prior to reversing due to insufficient funds or Transaction.
“ JavaScript
// Seolia-truffle-contracts.js
const web3 = require (‘web3’);
Const trufa = require (‘truffle’);
const web3 = new web3 (new web3.providers.httPProvider (“
module.