Call Us 786-865-0767

Ethereum Transaction RevertInstructionError: Transaction has been reverted by the EVM

I’ve encountered an error while attempting to use addLiquidity with Uniswap V2 on SEOlia testnet using web3.js in Truffle. The error is caused by a transaction being reverted by the Ethereum Virtual Machine (EVM). Here’s a detailed explanation of the issue and potential solutions.

The Issue:

When trying to execute addLiquidity on the Uniswap V2 interface, the EVM reverts the transaction. This can happen due to various reasons such as:

  • Insufficient liquidity in the pool.

  • Incorrect token balances or addresses.

  • Unvalidated external calls (e.g., calling functions from external contracts).

  • Incorrect gas limits.

The Code:

Here’s a sample Truffle contract and web3.js code snippet that reproduces the issue:

// seolia-truffle-contracts.js

const Web3 = require('web3');

const truffle = require('truffle');

const Web3 = new Web3(new Web3.providers.HttpProvider("

module.exports = {

providers: [], // No provider specified, causing EVM to revert transaction

networks: {

development: {

host: 'localhost',

port: 8545,

gas: 2000000

},

seolia: { network_id: 1 }

},

contracts: {

AddLiquidity: require('./AddLiquidity.json')

}

};

// addLiquidity.js

const Web3 = require('web3');

const contract = new Web3.eth.Contract(require.resolve('./AddLiquidity'), '0x...');

contract.methods.addLiquidity(address, amountIn, amountOut, price).send({ from: '0x...', value: '0.1' })

.then((result) => {

console.log(result.status);

if (result.status === 'success') {

contract.functions.getBalance.call(address)

.then((balance) => {

console.log(Balances: ${balance});

});

} else {

throw new Error('Error');

}

})

.catch((error) => {

console.error(error);

throw error;

});

Potential Solutions:

To resolve this issue, make sure to:

  • Specify a provider

    : Add a providers array with the EVM provider URL (e.g., in your Truffle configuration.


// seolia-truffle-contracts.js

const Web3 = require('web3');

const truffle = require('truffle');

const Web3 = new Web3(new Web3.providers.HttpProvider("

module.exports = {

providers: [],

networks: {

development: {

host: 'localhost',

port: 8545,

gas: 2000000

},

seolia: { network_id: 1 }

},

contracts: {

AddLiquidity: require('./AddLiquidity.json')

}

};

  • Validate external calls: Ensure that the externalCallfunction is implemented in your contract to validate external transactions.


// addLiquidity.js

const Web3 = require('web3');

const contract = new Web3.eth.Contract(require.resolve('./AddLiquidity'), '0x...');

contract.methods.addLiquidity(address, amountIn, amountOut, price)

.call({ from: '0x...' })

.then((result) => {

console.log(result.status);

if (result.status === 'success') {

contract.functions.getBalance.call(address)

.then((balance) => {

console.log(Balances: ${balance});

});

} else {

throw new Error('Error');

}

})

.catch((error) => {

console.error(error);

throw error;

});

  • Increase gas limits: Set higher gas limits to prevent the EVM from reverts due to insufficient funds or transaction complexity.

“javascript

// seolia-truffle-contracts.js

const Web3 = require(‘web3’);

const truffle = require(‘truffle’);

const Web3 = new Web3(new Web3.providers.HttpProvider(“

module.

Cryptoart Perpetual