0

I need to somehow transfer APT coins to another account from smart contract itself. Here is an issue, because transfer function needs &signer of an sender and that's why I can not send it from contract.

Is there any chance that I can send APT directly from contract itself inside a function by getting &signer somehow, or without it? I've read a lot of docs, search for it on GitHub and found nothing. I would appreciate any type of help. Regards!

AndRockSYS
  • 11
  • 2

1 Answers1

0

Likely the best way to achieve this is using a resource account. Resource accounts provide a different way to access signing capabilities.

For example, to get the signer for a resource account, you can call retrieve_resource_account_cap and create_signer_with_capability.

Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
  • Thank you for you help, I just want to make it clear, could you look at my implementation and tell me if it's gonna be safe Creating: `let signer_capability = resource_account::retrieve_resource_account_cap(owner, source_address); move_to(owner, Storage { data: vector::empty(), signer_capability: signer_capability,` Using: `let resource_signer = account::create_signer_with_capability(&storage.signer_capability); *winner = signer::address_of(account); aptos_account::transfer(&resource_signer, *winner, *pool);` Some of my code, Storage is a struct where rounds, events, etc. – AndRockSYS Apr 14 '23 at 10:00
  • It might be better to head to the Aptos Discord and ask this question so we can help you properly: https://discord.com/invite/aptoslabs. – Daniel Porteous Apr 14 '23 at 10:19