create_system_account.ts 748 B

123456789101112131415161718192021
  1. import { Account, Pubkey, Result, Signer, u8 } from '@solanaturbine/poseidon';
  2. export default class CreateSystemAccountProgram {
  3. static PROGRAM_ID = new Pubkey('2Gs21s6ovwaHddKdPZvGpowpVJJBohdy3DrjoX77rqiY');
  4. //Create a new system account
  5. createSystemAccount(account: AccountState, owner: Signer): Result {
  6. //We use derive to define the account and chain the `.init()` at the end for creating the account
  7. account.derive(['account']).init();
  8. //Set owner of the account
  9. account.owner = owner.key;
  10. // Store bump for the account
  11. account.accountBump = account.getBump();
  12. }
  13. }
  14. export interface AccountState extends Account {
  15. owner: Pubkey; // Owner of the account
  16. accountBump: u8; // Bump for the derived account
  17. }