12345678910111213141516171819202122232425262728293031323334353637 |
- import "./system_instruction.sol";
- @program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
- contract pda_rent_payer {
- bool private value = true;
- @payer(payer) // "payer" is the account that pays for creating the account
- @seed("rent_vault") // hardcoded seed
- @bump(bump) // bump seed to derive the pda
- constructor(address payer, bytes1 bump, uint64 fundLamports) {
- // Independently derive the PDA address from the seeds, bump, and programId
- (address pda, bytes1 _bump) = try_find_program_address(["rent_vault"], type(pda_rent_payer).program_id);
- // Verify that the bump passed to the constructor matches the bump derived from the seeds and programId
- // This ensures that only the canonical pda address can be used to create the account (first bump that generates a valid pda address)
- require(bump == _bump, 'INVALID_BUMP');
- // Fund the pda account with additional lamports
- SystemInstruction.transfer(
- payer, // from
- address(this), // to (the address of the account being created)
- fundLamports // amount of lamports to transfer
- );
- }
- function createNewAccount(uint64 lamports) public {
- AccountInfo from = tx.accounts[0]; // first account must be an account owned by the program
- AccountInfo to = tx.accounts[1]; // second account must be the intended recipient
- print("From: {:}".format(from.key));
- print("To: {:}".format(to.key));
- from.lamports -= lamports;
- to.lamports += lamports;
- }
- }
|