0

In my contract I receive BNB from users and would like to transfer (withdraw) it to a gnosis safe address.

The function works with a normal address but does not seem to work with a "contract" address.

The following line of code breaks with "out of gas" when using a “contract” address

payable(profitAddress).transfer(profit);
  • profitAddress: a gnosis safe address

And I follow those articles https://help.gnosis-safe.io/en/articles/5249851-why-can-t-i-transfer-eth-from-a-contract-into-a-safe, Transferring ETH from contract to Safe, it still not work.

const { ethers } = require('ethers')
// eslint-disable-next-line import/no-extraneous-dependencies
require('dotenv').config()

const provider = new ethers.providers.JsonRpcProvider(
  'https://rpc.tenderly.co/fork/6e26dd40-d373-4867-bbc4-892a45787425',
  {
    name: 'BSC',
    chainId: 56
  }
)

async function run() {
  let wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
  wallet = wallet.connect(provider)
  const nft = new ethers.Contract(
    '0xBa9F0a830E89D4b8378d266da79BE32BD6c37458',
    ['function withdraw(address to) public'],
    wallet
  )
  const overrides = {
    gasLimit: 500000,
    gasPrice: ethers.utils.parseUnits('150', 'gwei').toString(),
    type: 1,
    accessList: [
      {
        address: '0xd5530Ea6d5832b9BACa571A66AB4051680645292', // admin gnosis safe proxy address
        storageKeys: [
          '0x0000000000000000000000000000000000000000000000000000000000000000'
        ]
      },
      {
        address: '0x3E5c63644E683549055b9Be8653de26E0B4CD36E', // gnosis safe master address
        storageKeys: []
      },
      {
        address: '0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552', // gnosis safe master address
        storageKeys: []
      }
    ]
  }

  const tx = await nft.withdraw(
    '0x5A25944B3383Aab4f3B830d5D9f2Ba672D9fa9Ce',
    overrides
  )
  console.info({ tx })
  const resolved = await tx.wait()
  console.info({ resolved })
}

run()

Thanks!

0

2 Answers 2

1

This is a duplicate of Send ETH from a contract to a Gnosis Safe wallet on BSC/BNB

As mentioned there you can find a guide here: https://github.com/rmeissner/safe-migrator

Make sure to review all code in this guide, as the use is always at your own risk.

Note: BNB does not support the access list feature and does not plan to (see Does bsc chain support eip2930?)

1

The Solidity .transfer function transfers 2300 gas to the designated address. Apparently when the designated smart contract receives a transaction the smart contract uses more than 2300 gas . So you have to send more gas, this can be achieved with the Solidity .call function.

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