38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { Connection, PublicKey, Keypair, clusterApiUrl, LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
import { Bets } from "./bets";
|
|
import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
|
|
import { clusterUrl, cocSk, getRandomInt, testerSk } from "./shared";
|
|
const IDL = require('./bets.json');
|
|
|
|
async function create(){
|
|
const keypair = Keypair.fromSecretKey(Uint8Array.from(testerSk));
|
|
const connection = new Connection(clusterUrl);
|
|
const provider = new AnchorProvider(connection, new Wallet(keypair));
|
|
const program:Program<Bets> = new Program<Bets>(IDL,provider);
|
|
|
|
let solBalance = (await connection.getBalance(keypair.publicKey))/ LAMPORTS_PER_SOL;
|
|
console.log(`Tester ${keypair.publicKey} has ${solBalance} SOL`);
|
|
if(solBalance <= 1){
|
|
console.log("Requesting airdrop due to insufficient funds");
|
|
try{
|
|
await connection.requestAirdrop(keypair.publicKey, 5);
|
|
}catch{
|
|
console.log("Airdrop failed");
|
|
}
|
|
solBalance = await connection.getBalance(keypair.publicKey);
|
|
console.log(`Tester now has ${solBalance} SOL`);
|
|
}
|
|
|
|
const [bet_list_pda] = await PublicKey.findProgramAddress([Buffer.from("bets_list")], program.programId);
|
|
console.log(`Bets list PDA : ${bet_list_pda}`);
|
|
const nonce = getRandomInt(100000000000);
|
|
const tx = await program.methods.createBet(new BN(100000000),"tester", "tetris", new BN(nonce)).accounts({
|
|
betsList: bet_list_pda,
|
|
}).rpc();
|
|
console.log(`create tx : ${tx}`);
|
|
await connection.confirmTransaction(tx);
|
|
|
|
console.log(`tx complete`);
|
|
}
|
|
|
|
create(); |