DEV Community

Cover image for How to create a smart contract to receive payments

How to create a smart contract to receive payments

Emanuel Ferreira on September 05, 2021

With the ascendancy of blockchains and cryptocurrencies you do not want to be left out of this right? In this article I will teach to you how to c...
Collapse
 
cibrax profile image
Cibrax

A few things. The owner might be who deployed the contract but not the one expecting the donations. Anyone can call your donate method. If the address points to another contract that could give errors, your eth will be burned/lost. Transfer is not recommended anymore. You should use Call and check for the result. If the result is false, you revert the transaction. Great start anyways!

Collapse
 
emanuelferreira profile image
Emanuel Ferreira

thanks, i will make these fixes!!

Collapse
 
emanuelferreira profile image
Emanuel Ferreira

I made these corrections in case you want to check

Collapse
 
cibrax profile image
Cibrax

Yes, that is perfect!

Collapse
 
victorquanlam profile image
Victor Quan Lam

It would be amazing if there're a bit more details on hosting the contract on testnest and mainnest. But it's still a great article. Keep up the good work mate

Collapse
 
emanuelferreira profile image
Emanuel Ferreira

Thanks for the feedback, I will create an article to make a deploy for the testnet!!

Collapse
 
victorquanlam profile image
Victor Quan Lam

cool! deploying to the main nest is a pain actually. The gas fee is insane nowadays.

Collapse
 
olanetsoft profile image
Idris Olubisi💡

Nice post.

I have a questiopn please, i tried running the test locally to test my contract but i keep getting this error "Failed to send money" what do you think could be the casue pls. @emanuelferreira

Collapse
 
emanuelferreira profile image
Emanuel Ferreira

Thank you!

how are you sending money using the web3? you need to pass the value on your web3 call function.

Collapse
 
eed6d7872f6537 profile image
Ben Sigman

Thanks for the example. I was trying to out this contract, but I keep getting a weird error - I'm sure it's something simple that I'm missing here.

I deployed to Rinkeby Testnet using remix... then I loaded the contract and ABI into app.mycrypto.com/interact-with-con... - but when I try to send a donation, I keep getting this error:

"Something went wrong: insufficient funds for intrinsic transaction cost. Make sure you've filled everything out correctly and try again. If this error persists, please visit our Knowledge Base for further assistance."

I have plenty of test ETH in my account. I have tried to send ETH directly to the contract and it also fails. What am I doing wrong?

Collapse
 
eed6d7872f6537 profile image
Ben Sigman

One strange thing is that I can make a donation of "0 ETH" but if I add ANY amount - such as 0.0001 ETH - I get the same error as above. Gas costs are only 0.000094ETH so it really can't be the issue. Does my contract need to be deployed with ETH in it?

Collapse
 
roni_sommerfeld profile image
RoNi Sommerfeld

Hello, is it possible to use an ERC20 token inside a function of an ERC721 token?
To better explain what I want to do is as follows.
Before minting an ERC721 token (Item of my game) I want to check if the player has my token (ERC20) in his wallet, if he has he could mint it...
Is it possible to do that? Thanks.

Collapse
 
emanuelferreira profile image
Emanuel Ferreira

Hey RoNi, yes!

on your ERC721 mint function you need to connect with your ERC20 contract and verify the balance of the user

Collapse
 
juliomerisio profile image
Julio Merisio

sick bro! Keep going!

Collapse
 
axenwhcr4097 profile image
AxenWhCr4097

Can make a donate in USDT instead of ETH ?