CRYPTOCURRENCY

Ethereum Transaction RevertInstructionError: Transaction was reverted by EVM

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

The issue:

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

  • Insufficient liquidity in the wallet.
  • Incorrect token balances or addresses.
  • Unvalidated external calls (e.g. calling external contract functions).
  • Incorrect gas limits.

The Code:

Here is an example Truffle contract and a web3.js code snippet that reproduces the issue:

//send truffle-contracts.js

const Web3 = require('web3');

const truffle = require('trufa');

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

module.exports = {

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

networks: {

development: {

host: 'localhost',

port: 8545,

hate: 2,000,000

},

address: {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, quantityIn, quantityOut, 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.

//envia trufa-contracts.js

const Web3 = require('web3');

const truffle = require('trufa');

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

module.exports = {

providers: [],

networks: {

development: {

host: 'localhost',

port: 8545,

hate: 2,000,000

},

address: {network_id: 1}

},

contracts: {

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

}

};

  • Validate external calls: Make sure 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, quantityIn, quantityOut, 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 EVM rollback due to insufficient funds or transaction complexity.

“javascript

//send truffle-contracts.js

const Web3 = require(‘web3’);

const truffle = require(‘trufla’);

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

module.