Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coral-xyz/anchor

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coral-xyz/anchor

Anchor client

  • 0.30.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105K
decreased by-22.14%
Maintainers
0
Weekly downloads
 
Created

What is @coral-xyz/anchor?

@coral-xyz/anchor is a framework for Solana's Sealevel runtime providing several developer tools to build, deploy, and interact with smart contracts on the Solana blockchain. It simplifies the process of writing Solana programs by offering a set of Rust macros and a TypeScript client for interacting with these programs.

What are @coral-xyz/anchor's main functionalities?

Smart Contract Development

This code demonstrates how to set up a client to interact with a Solana smart contract using the @coral-xyz/anchor framework. It shows how to load the program's IDL, set up a provider, and call a function on the smart contract.

const anchor = require('@coral-xyz/anchor');

// Define the provider
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

// Load the IDL
const idl = JSON.parse(require('fs').readFileSync('./target/idl/my_program.json', 'utf8'));

// Address of the deployed program
const programId = new anchor.web3.PublicKey('YourProgramPublicKey');

// Generate the program client from IDL
const program = new anchor.Program(idl, programId);

// Interact with the program
async function main() {
  // Call a function from the smart contract
  await program.rpc.initialize();
}

main().catch(err => console.error(err));

Testing Smart Contracts

This code provides a basic test setup for a Solana smart contract using the @coral-xyz/anchor framework. It uses Mocha for testing and demonstrates how to initialize a program and assert the state of an account.

const anchor = require('@coral-xyz/anchor');
const assert = require('assert');

describe('my-program', () => {
  // Configure the client to use the local cluster.
  const provider = anchor.AnchorProvider.local();
  anchor.setProvider(provider);

  const program = anchor.workspace.MyProgram;

  it('Initializes the account', async () => {
    // Add your test here.
    const tx = await program.rpc.initialize();
    console.log('Transaction signature', tx);

    // Fetch the account and assert its state
    const account = await program.account.myAccount.fetch(provider.wallet.publicKey);
    assert.ok(account.data.eq(new anchor.BN(0)));
  });
});

Other packages similar to @coral-xyz/anchor

FAQs

Package last updated on 20 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc