Hey @ArvidK,
Oh dear, that’s frustrating that it still isn’t working for you Let’s see if we can sort it…
I have copied and pasted the latest code you’ve posted into my copy of the contract in Remix and it compiles and executes no problem, so there isn’t any problem with your code. The only thing I had to change was the quotes around the error message “Insufficient funds”
to "Insufficient funds"
. But you probably have the correct quotes in your code, anyway, and that’s probably just an error when copy-and-pasting into the forum post editor.
Before you deploy your contract, I assume that the compiler isn’t giving you any red errors, is that correct? You’ll proabably always get 1 orange warning about the SPDX license identifier not being provided, but you can ignore that one. But if you get any other orange warnings then we should probably look at what those are saying.
If the compiler errors or warnings aren’t the problem, then we need to think carefully about what’s causing the transaction error you are getting when trying to call the transfer function. The transaction is being reverted so the cause should be either one of the require statements, or the assert statement. It can’t be the 1st require statement, because then the error message would also include the message "Insufficient funds"
. Unfortunately, without putting a personalised error message as the 2nd argument in a require statement, the complete transaction error message will be exactly the same for require() and assert(). You could try adding another personalised error message to the 2nd require statement and then you will be able to see exactly which one is throwing (2nd require, or the assert).
If the 2nd require() is throwing, then it may be because you are calling the function from the same address that you are inputting as the recipient (1st argument). This can be an easy mistake to make because you need to select the recipient address from the account dropdown, copy it (to input as the 1st argument) but then remember to change the dropdown back to the address you are transferring from before clicking to call transfer()
.
If you establish that assert() is throwing, instead, then we need to think again, because from the code you have posted, there is no way assert() should throw.
If none of my above suggestions resolve the problem, then post your complete contract, so I can test that.
Let me know how you get on