Search code examples
aptos

How do I transfer APT to an account that doesn't exist on-chain yet?


As I understand it, if you transfer APT to an account that doesn't exist on-chain yet, doing so will create the account on-chain. I've been trying to use 0x1::coin::transfer, but that doesn't seem to work.

Move abort in 0x1::coin: ECOIN_STORE_NOT_PUBLISHED(0x60005): Account hasn't registered `CoinStore` for `CoinType`

What should I do instead?


Solution

  • This is a bit confusing but there are two different functions.

    • This one only transfers coins if the account already exists on-chain: 0x1::coin::transfer. Code.
    • This one will create the account first if it doesn't exist yet: 0x1::aptos_account::transfer. Code.

    You can see in the second code link that it first checks if the account exists and creates it if it doesn't, and then calls 0x1::coin::transfer.