What is seed in PublicKey.createWithSeed(..) for?

I’m going through the hello world Solana tutorial, and I’ve noticed that this method needs a seed. The full code looks like below:

  // Derive the address (public key) of a greeting account from the program so that it's easy to find later.
  const GREETING_SEED = 'hello';
  greetedPubkey = await PublicKey.createWithSeed(

I wonder if anyone can explain briefly what the seed is for and what happens if I provide a different seed (also, when/why will I do that?)

Thank you!

Hi @t4n1n and welcome to the forum! :wave:

The idea behind createWithSeed is to create an address that your program owns that is somehow associated to another address. The hello seed is used to make that address unique.

So, for instance, you could create a “hello” address and a “goodbye” address or any other seeds that pretty much represent what you are going to want to use that address for.

Another way to put it would be that you are creating the payers “hello” address and giving the program write access to that address.

Let me know if that doesn’t make sense, I’m having a hard time explaining that one. :slight_smile:

Thank you for your answer. I’m still wrapping my head around it.

In practice, do I need to save the seed somewhere in order to retrieve the same public key?

I don’t think you need to save the seed, usually, because its most-often like a hard-coded value. The seed is specific to the purpose that you will use that generated address for.

I think I need a more concrete example to explain. What tutorial are you following? Why is it creating the greetedPubkey?

Maybe it will help if I can tell why the tutorial even wants to generate the derived account so I can explain it better.

Thank you for helping me with this. Here’s the tutorial I’m looking at: GitHub - solana-labs/example-helloworld: Hello world on Solana

It creates a derived account from the payer account.

Unrelated question: where is the best place to ask more random small questions? For example, I look at a different example (solana-program-library/processor.rs at master · solana-labs/solana-program-library · GitHub), and it simply += or -= lamports, and I am confused about how an on-chain program can just plus or minus lamports of a signed account by any amount. How would this work with a wallet? because I certainly don’t want an on-chain program to decrease my held lamports by any amount. There must be a way to limit this. I’m not sure where to ask this kind of question.

Thank you again for helping me!

Glad I can help! I’m going to try to look closer at this once I get the chance.

Well, I’m unfortunately the only one here on the forum answering questions, but feel free to post any random questions here and I’ve got a pretty good chance of having the answer. :slight_smile: The more questions I answer the more likely I’ll have the answer to the next person’s question.

Otherwise, for development topics there’s the Solana Discord, which is more active with developers.

:warning: Warning: Telegram and Discord and other messaging platforms are a haven for people trying to scam you. Never give anybody your seed phrase or private key. Even support officials and admins will never ask for your seed phrase or private key. And never use a wallet app that you have not used before if somebody asks you to. They will fake a real wallet and use the fake wallet to steal all of your tokens.

In the example you gave, you just signed an instruction that can += or -= your lamports by any amount. But in reality, if you don’t want to do this, you can simply set a limit in the instruction.
I think you’ll want to read about rent exemption.