Skip to content

Commit

Permalink
adds transfer sol script
Browse files Browse the repository at this point in the history
  • Loading branch information
solanoepalacio committed Apr 9, 2024
1 parent 9521ad1 commit 983508b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
38 changes: 38 additions & 0 deletions token-dispenser/ts/scripts/transfer-sol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
PublicKey,
SystemProgram,
ComputeBudgetInstruction,
ComputeBudgetProgram,
} from "@solana/web3.js";
import { ledgerSignAndSend } from "./helpers";
import { connection, getSigner, getEnv } from "./env";
type Config = {
to: PublicKey;
amount: bigint; // lamports
};

(async () => {
const config: Config = {
to: new PublicKey(getEnv("TO")),
amount: BigInt(getEnv("AMOUNT")),
};

const signer = await getSigner();
const signerPk = new PublicKey(await signer.getAddress());

const transferIx = SystemProgram.transfer({
fromPubkey: signerPk,
toPubkey: config.to,
lamports: config.amount,
});

const setComputePriceIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1_200_000,
});

console.log(`Transferring ${config.amount} lamports to ${config.to.toBase58()}`);
const result = await ledgerSignAndSend([setComputePriceIx, transferIx], []);
console.log("Tx Sent: ", result);
const txIncluded = await connection.confirmTransaction(result);
console.log("Tx Included");
})();
16 changes: 4 additions & 12 deletions token-dispenser/ts/scripts/transfer-treasury.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import {
PublicKey,
SystemProgram,
AddressLookupTableProgram,
SYSVAR_INSTRUCTIONS_PUBKEY,
} from "@solana/web3.js";

import { TokenDispenserSdk } from "../sdk";
import { ledgerSignAndSend, ledgerSignAndSendV0 } from "./helpers";
import { connection, getSigner, getEnv } from "./env";
import { funders, tokenDispenserProgramId, treasuries } from "./config";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
AuthorityType,
TOKEN_PROGRAM_ID,
createSetAuthorityInstruction,
} from "@solana/spl-token";

import { ledgerSignAndSend } from "./helpers";
import { connection, getSigner, getEnv } from "./env";

type Config = {
treasury: PublicKey;
newAuthority: PublicKey;
Expand All @@ -30,7 +23,6 @@ type Config = {
const signer = await getSigner();
const signerPk = new PublicKey(await signer.getAddress());

// AuthorityType.AccountOwner;
const setAuthorityIx = createSetAuthorityInstruction(
config.treasury,
signerPk,
Expand All @@ -39,7 +31,7 @@ type Config = {
);

console.log(`Setting account ${config.treasury.toBase58()} authority to ${config.newAuthority.toBase58()}`);
const result = await ledgerSignAndSendV0([setAuthorityIx], []);
const result = await ledgerSignAndSend([setAuthorityIx], []);
console.log("Tx Sent: ", result);
const txIncluded = await connection.confirmTransaction(result);
console.log("Tx Included");
Expand Down

0 comments on commit 983508b

Please sign in to comment.