1

Total newbie here. So I deployed a contract and already did the flash loan, but now I want to withdraw the remaining funds that I deposited into the smart contract (for the premium fee). How do I actually execute this function, and where do I do it?

Do I just throw this function in a script and run it, do I somehow call the function in the terminal?

On etherscan, I was looking for the write section of my contract but I couldn't find the ability to withdraw the funds from there, so I am just a bit confused as to how I can actually interact with this contract. (i.e transferOwnership, withdraw, transferFrom, etc...)

Here is a pic of the withdraw code

enter image description here

And here is how the architecture of the code is

enter image description here

2 Answers 2

0

If you want to do a transaction with a deployed smart contract, you need to interact with it on the blockchain level. There is many ways to do it. For example you can use MyEtherWallet.

You can deploy your contract on MainNet (it cost you ETH), but there is other testnet network such as Ropsten. You can also upload it into a local blockchain with RemixIDE (browser) or Geth etc.

MyEtherWallet can handle data to "make" the transaction on any network. But you need two parameters :

  • Contract address.
  • Contract ABI (i.e "how to use this smart contract" for wallet)

Then you need a wallet that secure your private key to "sign" this transaction and send it to the network.

1
  • Wow, thanks for the reply. This looks exactly like what I needed (working on the Kovan network and I can't seem to verify any of my contracts). When I put in my Contract address, it recognizes it and displays a green checkmark next to it. When I put in the ABI, however, that green checkmark never shows up and I cannot continue. Any thoughts? Commented Jun 2, 2021 at 4:09
0

So I have been working on it and can now confirm that this is working. First off, I would want to start with how you are using the ERC20 smart contract library. This library is used when you are trying to Create a new ERC20 token. Looking at the image that you have posted. It seems you are attempting to deal with an existing token (which is of type ERC20)

Using the IERC20 smart contract (which is an interface) allows you to interact with an ERC20 token that has already been created. All you need is the address of the token contract (which created the token or the one that provides the token -- like a faucet)

Next, msg.sender.transfer() no longer works. It is deprecated or removed idk. You could use payable(msg.sender).transfer() to remove the errors. However, do not. That is because if you run this on even a testnet, you will see that the function is likely to fail (which it will) and you WILL lose your funds.

An alternative, therefore is to use the inbuilt function transfer from the IERC20 interface.

First,

  • inherit (import) the IERC20 interface
  • get the token contract address (of the token that you are using)
  • type cast the token address into IERC20 and store it inside another variable (for convenience) IERC20 token = IERC20(<tokenAddress>)
  • Now, using the variable, you can call all of the functions of the ERC20 token
  • We will be using the 'transfer' function as follows:
  • token.transfer(msg.sender, token.balanceOf(address(this)));
  • above function allows you to transfer tokens to self (with the 'msg.sender' keyword). It is possible to send the tokens to some other address by simply entering the address of the contract/account you wish to transfer these funds to.

Note: These statements are to be written inside a function. They don't work outside the function. You could use the function's parameters to set the values for address to which the funds are to be sent, as well as the amount that is to be sent.

Your Answer

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

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