0

I have a simple ERC20 token, and I would like to transfer the ownership of this contract onto a new address using the Ownable.sol transferOwnership() function

When I run this contract, it seems that this function call is going to cost me approximately 1.5 ETH (!!!) if I use a competitive Gas Price (215 GWEI). That seems very expensive considering its my understanding that all that is happening is one variable is being updated on the blockchain.

Am I running something wrong? Here is the etherscan information, I have tried to run it with a very low gas fee but it still seems to cost 0.15ETH (it will probably never be added to a block at this price)

https://etherscan.io/tx/0xb9c184899d8d19e53464509aabd3383508a2320ea67613d3f327a393d8961999

Here is my code:

const Web3 = require('web3');
const TestToken= artifacts.require('TestToken.sol');
const web3 = new Web3('https://ropsten.infura.io/v3/<MYKEY>');

module.exports = async function (deployer, network, accounts) {
  const ADMIN_ADDRESS = "...";
  const NEW_ADMIN = "...";


  const TEST_TOKEN= await TestToken.at("...");
  console.log('TEST governance token address: ' + TEST_TOKEN.address);

  const TEST_OWNER = await TEST_TOKEN.owner();
  
  console.log('The owner of the TEST governance token is: ' + TEST_OWNER);
  console.log('Transferring Ownership Now');
  
  let result = await TEST_TOKEN.transferOwnership(NEW_ADMIN);
  const NEW_TEST_OWNER = await TEST_TOKEN.owner();


  console.log('The new owner of the TEST governance token is: ' + NEW_TEST_OWNER);

1 Answer 1

0

You are right, the transferOwnership function only changes the state of a single variable on the contract so it shouldn't require too much gas. The expensive part is that it emits an event, which actually stores data on a block and that is actually expensive.

One possible solution is that you could wait until EIP-1559 is merged into mainnet which should make gas fees decrease up to 100x, or if you are making your own implementation of the ERC20Token, you could just remove the event emission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.