0

Hello i m learning vyper and i have this issue: I deployed a standard ERC20 token contract using vyper default contract: https://github.com/ethereum/vyper/blob/master/examples/tokens/ERC20.vy

When i write my own contract to interact with it i have an issue transfering tokens from the current address that has tokens to the desired address, here is the code that i wrote in vyper to do the transfer:

contract Pcoin():
    def transfer(_to : address, _value : uint256) -> bool: modifying

@public
def transfer(_token_contract: address, _to: address, _value: uint256) -> bool:
    return Pcoin(_token_contract).transfer(_to, _value)

When i call the transfer method i get a failed transaction. I tried also using the transferFrom method:

contract Pcoin():
    def transferFrom(_from : address, _to : address, _value : uint256) -> bool: modifying

@public
def transfer(_token_contract: address, _from: address, _to: address, _value: uint256) -> bool:
    return Pcoin(_token_contract).transferFrom(_from, _to, _value)

Also no luck with that.

Can someone please point out what i m doing wrong, Thanks :)

9
  • Are you sure your contract holds a sufficient token balance? (Does it own at least _value tokens?) Or in the transferFrom case, are you sure your contract has a sufficient allowance set by the _from address?
    – user19510
    Sep 29 '19 at 19:47
  • @smarx Thanks for the reply, when i call the transfer method i m calling it from an address that has more than 900 tokens and i m sending 1 as _value. In the transferFrom case i have previously called the approve method from the token contract directly to add the _spender address and a _value to the allowances map
    – Andy
    Sep 29 '19 at 19:58
  • Sorry, but which address has the tokens? There are three addresses involved: the Pcoin contract, the contract you've shared here (let's call that contract Foo), and the account that's invoking Foo.transfer. So you call Foo.transfer, and then it calls Pcoin.transfer. For that second call to work, Foo must have a sufficient balance of Pcoins.
    – user19510
    Sep 29 '19 at 20:04
  • @smarx The address that has the tokens is the address that is calling Foo.transfer, the contract Foo does not have any variable that is holding tokens, should it have it?
    – Andy
    Sep 29 '19 at 20:10
  • 2
    Well, you can use transferFrom in that case. Just make sure the _from address has called Pcoin.approve(Foo, <amount>) first.
    – user19510
    Sep 29 '19 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.