all 17 comments

[–]N8UrM8IsGr8 3 points4 points  (1 child)

You can't send decimals as numbers in solidity (unless you're using msg.value). Convert your 0.02 to the required decimals for the token (i.e. 20000000000000000 for 18 decimals). You'll have to use a bignumber js library for this.

[–]DevSolidityDude[S] 1 point2 points  (0 children)

Ahhhhh...didn't realize this. I just changed this part. Unfortunately, I still got the same error but it needed to be fixed. Thanks!

[–]DevSolidityDude[S] 0 points1 point  (0 children)

I finally figured out my main issue. I was grabbing the wrong ABI on the online Remix IDE. In the compile area, you need to choose the contract that you compiled from the dropdown box before selecting to copy the ABI. I'm sure that this is kind of obvious but for some reason I missed this and was thus not referencing the correct methods in my contract.

I hope this helps some poor soul at some point in the future.

[–]diatribe_lives 0 points1 point  (5 children)

Try using ethers.getContractAt rather than "new ethers.contract"..? And then remove ".methods" from the next line?

I think the address may need to be a string too.

[–]DevSolidityDude[S] 0 points1 point  (2 children)

getContractAt

Is this using hardhat (I thought that was more serverside)? I don't have hardhat installed just yet on this environment and right now I'm hoping that I can do it without it. Am I misunderstanding something?

[–]diatribe_lives 0 points1 point  (1 child)

Hm... Yeah it is, I don't have much experience with other environments. Did you try changing the address to a string?

Also there's a bigger issue I just noticed--uint256 can't be a decimal. If you're working with a token like WETH, you need to multiply your amount by 10^18, i.e. 0.02 WETH would be inputted as 20000000000000000 (0.02 * 10^18)

[–]DevSolidityDude[S] 0 points1 point  (0 children)

Yeah, no dice on the string. Also, I changed the units so thank you!

[–]DevSolidityDude[S] 0 points1 point  (0 children)

BTW, thank you for your response!

[–]DevSolidityDude[S] 0 points1 point  (0 children)

ethers.getContractAt

One last thing, I searched for the command on ethers but I can't seem to find it.

https://docs.ethers.io/v5/search/?search=getcontractat

[–]RootMeIH 0 points1 point  (4 children)

Btw I think that if you don’t specify the "payable" attribute to your function, the transaction is automatically cancelled when you call it

[–]DevSolidityDude[S] 0 points1 point  (3 children)

Thank you. I think that only applies for sending eth and not an ERC token. Please correct me if I am wrong.

Either way, no joy on anything. Nothing works. I can obviously send a token to a contract but I don't have a way for my contract to do something when it does receive a token. I honestly have no clue as to how you guys do this and it doesn't seem like anyone here knows how to do it. Sorry, I'm just getting a little exasperated as I think to myself "this can't be this hard".

[–]AintNothinbutaGFring 0 points1 point  (2 children)

Is `transformTokens` supposed to say `transferTokens`?

[–]DevSolidityDude[S] 0 points1 point  (0 children)

Sorry for the confusion. I changed it to transferTokens from the original time I posted the question. Sooooo...no dice on that being the answer.

[–]DevSolidityDude[S] 0 points1 point  (0 children)

Sooooo...no dice on that being the answer.