Skip to content

Commit

Permalink
Add deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
tevdoradze committed Oct 23, 2022
1 parent d6f3962 commit 5506d57
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ seeds = false
[programs.localnet]
casier = "FLoc9nBwGb2ayzVzb5GC9NttuPY3CxMhd4KDnApr79Ab"

[programs.mainnet]
casier = "CAsieqooSrgVxhgWRwh21gyjq7Rmuhmo4qTW9XzXtAvW"

[registry]
url = "https://anchor.projectserum.com"

Expand Down
56 changes: 53 additions & 3 deletions migrations/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,61 @@
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@project-serum/anchor");
import * as anchor from "@project-serum/anchor";
import { Program, AnchorProvider, Wallet } from "@project-serum/anchor";
import { Casier } from "../target/types/casier";
import {
PublicKey,
Connection,
Keypair,
SystemProgram,
SYSVAR_RENT_PUBKEY,
} from "@solana/web3.js";
import * as fs from "fs";

module.exports = async function (provider) {
function loadKeypair(keypairPath: string): any {
return <any>JSON.parse(fs.readFileSync(keypairPath).toString());
}

function loadWallet(keypair: string): Keypair {
return Keypair.fromSecretKey(new Uint8Array(loadKeypair(keypair)));
}

const fee_payer = loadWallet(process.env.FEE_PAYER_KEY_PATH);

module.exports = async function () {
// Configure client to use the provider.
anchor.setProvider(provider);
const idl = JSON.parse(
require("fs")
.readFileSync(`${process.cwd()}/../target/idl/casier.json`, "utf8")
.toString()
);
const connection = new Connection(process.env.RPC_ENDPOINT, "recent");
const wallet = new Wallet(fee_payer);
const provider = new AnchorProvider(connection, wallet, {
commitment: "recent",
});
const program = new Program<Casier>(
idl,
new PublicKey("CAsieqooSrgVxhgWRwh21gyjq7Rmuhmo4qTW9XzXtAvW"),
provider
);
const tx1 = await program.methods.initialize().rpc();
console.log(tx1);
const [configPDA] = await PublicKey.findProgramAddress(
[anchor.utils.bytes.utf8.encode("config")],
program.programId
);
const tx2 = await program.methods
.initConfig()
.accounts({
config: configPDA,
feePayer: fee_payer.publicKey,
systemProgram: SystemProgram.programId,
rent: SYSVAR_RENT_PUBKEY,
})
.rpc();
console.log(tx2);

// Add your deploy script here.
};

0 comments on commit 5506d57

Please sign in to comment.