ERC-20 Token Swap | Solidity (0.6)

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 57

  • @jeffe9349
    @jeffe9349 4 роки тому +8

    Can't one side still cheat on the trade though? Since both people in the trade are able to call the swap() function and only one signature is needed, couldn't I just tell the other person to give allowance to the TokenSwap smart contract first. Then I can come in and just call swap() and put 0 as my amount and then whatever allowance the other person gave for the other amount? I do not know if I am missing something, just want to be sure. If this is the case, I believe this could be fixed requiring both parties to sign on the swap() function. Let me know! Thanks for the great videos by the way!

    • @smartcontractprogrammer
      @smartcontractprogrammer  4 роки тому +1

      Yes you are absolutely right! This is a bug. I've fixed the code by setting the trading amounts inside the contract. Here is the code
      solidity-by-example.org/0.6/app/erc20/

    • @thaod.nguyen1124
      @thaod.nguyen1124 3 роки тому +1

      @@smartcontractprogrammer Hi, what is the file solution for this problem. I'm searching with 'swap' keyword and there is no result

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 роки тому +1

      @@thaod.nguyen1124
      solidity-by-example.org/app/erc20/

    • @odayalhalbe9257
      @odayalhalbe9257 2 роки тому

      @@smartcontractprogrammer Hi ,there is not code in this link ,can you please explain what you did exactly to fix problem ?

    • @odayalhalbe9257
      @odayalhalbe9257 2 роки тому

      I need the code before fix and after fix please

  • @jimmychu0807
    @jimmychu0807 2 роки тому

    This is a very cool tutorial on token swap. Thanks for the content.

  • @tharanijaiprakash792
    @tharanijaiprakash792 2 роки тому +1

    Hi sir i created erc20 tokens in gnosis, i need to bulk swap them for usdt , i don't know how to do it, if you help me i can pay thcv2 - a erc20 token i minted in gnosis chain and has liquidity in honeyswap.

  • @varunss1211
    @varunss1211 11 місяців тому

    by doing and giving the same parameters as you the code is showing token 1 allowance is less on swap why is this happening I have used the mytoken code and tokenswap same as in the description link

  • @StuartVinton
    @StuartVinton 3 роки тому

    This is exactly what I was looking for. Great tutorial; explained very well. Thank you!

    • @PínnedbyMoralisWeb3-c2x
      @PínnedbyMoralisWeb3-c2x 3 роки тому

      Thank you for watching, for question, guidance and support at anytime. Just DM +1.(4 .2 .3). 4 . 3 . 0 . 6 . 9 . 8 . 4 @ W H A T S A P...

  • @Ts2pc
    @Ts2pc 2 роки тому

    Why do you use IERC 20 here and ERC20 in last course?

  • @salem232
    @salem232 4 роки тому +3

    😍 this is supper cool stff !!! Token Swap is a very simple yet effective and creditable fuction !! It is almost like central clearing house in financial instructment trading ✨ Thanks so much !!

  • @lukhanyovena3297
    @lukhanyovena3297 2 роки тому

    Hello,
    Where did you get the token address from?

  • @imvivekkushwaha
    @imvivekkushwaha 2 роки тому

    What is token swap address , Bob coin address and alice coin address

  • @ArmWek
    @ArmWek 9 місяців тому

    hi friend i have tokens in ERC 20 network stuck with old contract can i manually copy them 1-1 to new contract

  • @neman715
    @neman715 3 роки тому

    How to add front end for this smart contract
    Im building mini project so looking for small token swap dapp reference

  • @horaciolampe166
    @horaciolampe166 3 роки тому

    Excellent video, thanks a lot!!!!!

  • @betterbehappythannot3605
    @betterbehappythannot3605 3 роки тому

    Why it shows in allowance that I have allowed the other acc to trade my tokens, but when i try to use the transferFrom function, it says that - amount exceeds allowance.

  • @alexanderchukwuma5183
    @alexanderchukwuma5183 3 роки тому

    How can I add binance smart contract to my token, i already have an ethereum contract but i still need to add a binance contract. please help me out

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 роки тому

      Ask here? He has experience on BSC
      ua-cam.com/channels/ZM8XQjNOyG2ElPpEUtNasA.html

  • @bchiniomar383
    @bchiniomar383 3 роки тому

    Hello , please i have a problem , i have 1 token erc20 THR , but i couldint to sell or trade , i want to serach solution to sell my Erc20 , can you give a solution please.
    Think you .

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 роки тому +1

      Google for an exchange to sell your tokens

    • @bchiniomar383
      @bchiniomar383 3 роки тому

      @@smartcontractprogrammer haw please ??

    • @PínnedbyMoralisWeb3-c2x
      @PínnedbyMoralisWeb3-c2x 3 роки тому

      @@bchiniomar383 Thank you for watching, for question, guidance and support at anytime. Just DM +1.(4 .2 .3). 4 . 3 . 0 . 6 . 9 . 8 . 4 @ W H A T S A P..

  • @EveAdam__1
    @EveAdam__1 3 роки тому

    Thank you very much !

    • @PínnedbyMoralisWeb3-c2x
      @PínnedbyMoralisWeb3-c2x 3 роки тому

      Thank you for watching, for question, guidance and support at anytime. Just DM +1.(4 .2 .3). 4 . 3 . 0 . 6 . 9 . 8 . 4 @ W H A T S A P...

  • @zackchen6280
    @zackchen6280 3 роки тому

    Okey okey, so hear me out... is the approval of spending coins revocable? Because if it was (e.g.) Bob calls swap() once both approved but then revokes his approval while the swap() function is still executing the first transaction -> and then the function is failing to transfer from Bob to Alice? Even though in practice this would be really hard to achieve, is it in theory possible? And if it is couldn't you prevent it this way:
    Alice sends the money to the contract and the exchange rate (she sends 10 AliceCoin and wants to receive 20 BobCoin) then Bob does the same (he sends 20 BobCoin and wants to receive 10 AliceCoin). After that the contract has the coins stored and sends them both their fair share.
    Just a thought. Your videos are really great and you make me really want to dig deeper into smart contracts!

    • @smartcontractprogrammer
      @smartcontractprogrammer  3 роки тому +3

      Given that the token contract is not malicious, no bug, etc...
      Attack probably won't work
      1. EVM is sequential. Only one transaction is executed at a time.
      2. swap is atomic. if any transfer fails the whole swap will fail.
      Revoking while swap is executing will fail because of 1.
      Revoking right before and or after swap is impossible from 2.
      Unless the token contract is malicious or faulty. In that case hack is probably possible.

    • @zackchen6280
      @zackchen6280 3 роки тому +1

      @@smartcontractprogrammer Ah, okey thank you for clarifying! I get it now :)

  • @when_life_gives_you_limes
    @when_life_gives_you_limes 2 роки тому

    Does this mean that every time 2 people wanna swap with each other, we have to deploy a new smart contract?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 роки тому

      Yes, or have a contract that can handle multiple swaps

    • @when_life_gives_you_limes
      @when_life_gives_you_limes 2 роки тому

      @@smartcontractprogrammer noted, maybe I'll create another smart contract & pass all the constructor parameters into the swap method instead so I can reuse the same contract.

    • @when_life_gives_you_limes
      @when_life_gives_you_limes 2 роки тому

      @@smartcontractprogrammer the problem that I am having with the contract in this tutorial is that I am unable to successfully approve both wallets for the swap.
      What I am trying to do here is whenever a user buys our custom token, user will have to approve the transfer, then our nodejs backend will automatically approve the transfer as well before the swap is executed.
      Everytime I tried, the swap fails with the error that our custom token's allowance is too low.

  • @abhisheksinha9027
    @abhisheksinha9027 4 роки тому

    Very useful 👍👍👍

    • @PínnedbyMoralisWeb3-c2x
      @PínnedbyMoralisWeb3-c2x 3 роки тому

      Thank you for watching, for question, guidance and support at anytime. Just DM +1.(4 .2 .3). 4 . 3 . 0 . 6 . 9 . 8 . 4 @ W H A T S A P...

  • @tobiassjoholm9325
    @tobiassjoholm9325 3 роки тому +1

    Use Adam and Bob

  • @solderine
    @solderine 3 роки тому

    can I hire you to create a smart contract for me?

  • @web3wizard381
    @web3wizard381 3 роки тому

    Jordan Peterson is that u

  • @anhdamat8224
    @anhdamat8224 4 роки тому

    I have loaded my bags for $SWAP on #MXC_Exchange below $1 price until now still holding. I think it might reach $1.5 soon!! Buy more $SWAP and hold it guys!! 🤑🤑

    • @PínnedbyMoralisWeb3-c2x
      @PínnedbyMoralisWeb3-c2x 3 роки тому

      Thank you for watching, for question, guidance and support at anytime. Just DM +1.(4 .2 .3). 4 . 3 . 0 . 6 . 9 . 8 . 4 @ W H A T S A P...

  • @cherriepie
    @cherriepie 2 роки тому

    Lol you sound like Jordan Peterson 😂

  • @kevinbabicz
    @kevinbabicz 2 роки тому +1

    Thank you!