0

I'm trying to figure out how to withdraw money from the contract within a smartpy entrypoint, and test the result in my scenario.

When I test the entrypoint:

  @sp.entry_point
  def withdraw(self, amount):
    sp.set_type(amount, sp.TMutez)
    sp.sender.transfer(amount)

I don't see the balance change in the scenario after the endpoint successfully executed when I check the contract.balance with sp.verify or scenario.show(c1.balance) or scenario.verify(c1.balance == sp.tez(...))

This was a solidity translation and the expression seems to work and run okay but it's not doing what I expect.

How can I withdraw from the contract or transfer contract balance to an account address in my smartpy entrypoint?

2

The correct way to do this is simply:

@sp.entry_point
def withdraw(self, amount):
    sp.set_type(amount, sp.TMutez)
    sp.send(sp.sender, amount)

The solidity translation tool I used didn't handle this properly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.