Skip to content

Instantly share code, notes, and snippets.

@vit0rr
Created December 17, 2021 12:55
Show Gist options
  • Save vit0rr/33715a4b5eabf3c67262a45b80adc5b5 to your computer and use it in GitHub Desktop.
Save vit0rr/33715a4b5eabf3c67262a45b80adc5b5 to your computer and use it in GitHub Desktop.
Solana program and test in JavaScript
use anchor_lang::prelude::*; // Import de algumas coisas
declare_id!("CJSaikztCUF1bMPhrLP1Q4GtGMNgEZ4ELb5qeVBBcB7s"); // Declara um id
#[program] // Define o programa - isso nos permite chamar no frontend dps
pub mod myepicproject { // pub mod é um modulo e nos permite definir varias funcoes e variaveis
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
// Funcao que recebe o contexto e produz o resultado
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize {} // aqui ele chama a funcao, que dentro dela, executa o Ok(())
const anchor = require('@project-serum/anchor');
const main = async() => {
console.log("🚀 Starting test...")
anchor.setProvider(anchor.Provider.env());
const program = anchor.workspace.Myepicproject;
const tx = await program.rpc.initialize(); // compila automaticamente nosso código lib.rs e implementa (essa é a funcao initialize la do lib.rs)
console.log("📝 Your transaction signature", tx);
}
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
};
runMain();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment