Sent tokens to unlock-protocol lock

I have sent ERC-20 tokens to created contract that is meant for locking content and releasing keys to people that pay. Apparently the contract has no ability to send the tokens but has a write command to send tokens to beneficiary (my wallet). Sorry if this sounds confusing, it’s hard for me to explain. There is a picture below showing of a command, can I not just write to the contract to withdraw those tokens as I own the contract?

Can you post your actual code? We could see what’s going wrong if you’re having a problem.

You will need to add functionality to the withdraw() command in order to send it to another address. Is this what you are wanting to do? You could make another withdraw function that would just withdraw it to another account when you call it.

If you don’t add functionality, the current withdraw just withdraws to a beneficiary. You will need to designate the beneficiary, otherwise it will just send it to the owner.

So this contract is created when I create a public lock, it’s intended for content creators to lock their content and people pay eth which goes directly to the contract, if the content creator wanted to collect the eth raised would they not have to send eth from the contract? This must have a withdraw function, can you tell if the withdraw function is proper?

Here’s the contract

I’m looking at this function in your code

function withdraw(address _tokenAddress, uint _amount) external onlyLockManagerOrBeneficiary
    uint balance = getBalance(_tokenAddress, address(this));
    uint amount;
    if(_amount == 0 || _amount > balance){
      require(balance > 0, 'NOT_ENOUGH_FUNDS');
      amount = balance;
      amount = _amount;

    emit Withdrawal(msg.sender, _tokenAddress, beneficiary, amount);
    // Security: re-entrancy not a risk as this is the last line of an external function
    _transfer(_tokenAddress, beneficiary, amount);

When the lock manager or beneficiary goes to use this function, it will first get the balance of those tokens stored in the contracts address.

If the amount is 0 or if the amount is greater than the balance, it will error out because of the require statement.

Otherwise it will set _amount to amount and continue to

_transfer, which will transfer the amount, to whatever address is stored in the

Whoever calls this function (lock manager or beneficiary) will need to pay the gas to do this transfer.

This is what should be happening, so according to the code it should work, as long as your beneficiary and lock creator is set correctly.

I would recommend uploading to a testnet and verifying the code works as intended before creating something live.

1 Like

Thank you very much for your help, I tried it and it worked!! This has really helped me and relieved a massive amount of stress, thank you very much. The main Dev of the unlock protocol was at no help at all and had told me that there was nothing I could do. Once again thank you