How to receive tez in an entrypoint?

I’m trying to get my contract to receive tez from sp.sender. How can I go about that?

Thank you!

If you’re using the IDE you can just add .run() to the transaction:

sc.entrypoint().run(sender = bob, amount = sp.mutez(1000))

When you will deploy the contract on chain you will have a specific label for that!

Thank, I actually think I also solved this one by adding a check:

sp.amount >= fee

In the contract:

Tez are received automatically.

There is no need to write anything to receive tez.

You can know how many tez are transferred to an entrypoint with sp.amount.
If you write an assert based on sp.amount, you can enforce the sending of a certain amount by the sender.
Example:

assert sp.amount > sp.tez(5), "NotEnoughtTez"

In the scenario:

c1.entrypoint().run(sender = alice, amount = sp.mutez(1000))
1 Like

very clear, thank you!