1

I am trying to follow the examples provided on the Solana website to create and implement a transfer-hook program. I have successfully built and deployed the example program provided here, then minted spl-tokens with the transfer-hook program using

spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --transfer-hook <TRANSFER_HOOK_PROGRAM_ID>

The guide then states you can can then initialize the transfer-hook account with the provided CLI from here using

spl-transfer-hook create-extra-metas <PROGRAM_ID> <MINT_ID> [<ACCOUNT_PUBKEY>:<ROLE> ...]

I understand that this will call the InitializeExtraAccountMetas function from the transfer hook program, but what specially belongs in [<ACCOUNT_PUBKEY>:<ROLE> ...]? Is this were I put the address of the account that holds the extra_account_metas? It is my understanding that at this point said account does not exist. Am I missing a step here?

1
  • I was able to successfully create the account using the provided cli. [<ACCOUNT_PUBKEY>:<ROLE> ...] is optional and is not needed for the example program. The cli will then create the account from the Program ID and the Mint ID using spl_transfer_hook_interface::get_extra_account_metas_address(token, program_id). I would appreciate if someone could write a more complete answer explaining this interface.
    – tonton
    Nov 20 at 14:31

1 Answer 1

1

You've figured it all out! The CLI will create the extra-metas account at the proper address, and the whole point of the [<ACCOUNT_PUBKEY>:<ROLE> ...] is to specify the additional accounts required by your transfer hook program to validate the transfer.

For example, your transfer hook program may want the instructions sysvar to make sure that it's only called in a certain way. In that case, you would run:

spl-transfer-hook create-extra-metas <PROGRAM_ID> <MINT_PUBKEY> Sysvar1nstructions1111111111111111111111111:readonly

And as long as people formulate their transfers properly, your transfer-hook program will also receive this account.

2
  • I assume this interface was created to make a standard way to initiate transfers. First derive token hook account from program id and token id, read the extra account metas from the token hook account, create a transfer_checked instruction with all the required addresses. Is this correct? Does this mean every wallet that wants to implement token22 (with transfer hooks) transfers need to also know the transfer hook program id? Or is there a way to derive this too?
    – tonton
    Nov 21 at 0:29
  • 1
    You've got it right. And the only way for a wallet to know the transfer hook program id is to fetch the mint account and read it from the data. There's no way to derive the transfer hook id
    – Jon C
    Nov 22 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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