Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@coral-xyz/anchor
Advanced tools
@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.
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)));
});
});
@solana/web3.js is a JavaScript API for interacting with the Solana blockchain. While it provides lower-level access to Solana's features, it lacks the higher-level abstractions and developer tools that @coral-xyz/anchor offers, such as IDL generation and client-side program interaction.
TypeScript client for Anchor programs.
@coral-xyz/anchor
depends on node.js native modules. Therefore, webpack 5 will not work with current version. You will either need to rollback to webpack 4, or use a polyfill for each missing dependency.[0.27.0] - 2023-03-08
MasterEditionAccount
account deserialization to spl metadata (#2393).InitSpace
derive macro to automatically calculate the space at the initialization of an account (#2346).env
option to verifiable builds (#2325).idl close
command to close a program's IDL account (#2329).idl init
now supports very large IDL files (#2329).transfer_checked
function (#2353).approve_checked
function (#2401).--skip-build
option to the verify command (#2387).--multithreaded
(#2321).async_rpc
a method which returns a nonblocking solana rpc client (#2322).rustls-tls
feature of reqwest
so that users don't need OpenSSL installed (#2385).VersionedTransaction
support. Methods in the Provider
class and Wallet
interface now use the argument tx: Transaction | VersionedTransaction
(#2427).--arch sbf
option to compile programs using cargo build-sbf
(#2398).Interface
and InterfaceAccount
types, related to token-2022 (#2386).AccountClient.fetchMultiple
match the account type being fetched (#2390)provider.simulate
will send the transaction with sigVerify: false
if no signers
are present (#2331).CpiAccount
, Loader
and ProgramAccount
(#2375).state
and interface
attributes (#2285).#[account(constraint = {})]
(#2379).account(zero_copy)
and zero_copy
attributes now derive the bytemuck::Pod
and bytemuck::Zeroable
traits instead of using unsafe impl
(#2330). This imposes useful restrictions on the type, like not having padding bytes and all fields being Pod
themselves. See bytemuck::Pod for details. This change requires adding bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]}
to your cargo.toml
. Legacy applications can still use #[account(zero_copy(unsafe))]
and #[zero_copy(unsafe)]
for the old behavior.createProgramAddressSync
, findProgramAddressSync
(now available in @solana/web3.js
) and update associatedAddress
to be synchronous (#2357).FAQs
Anchor client
The npm package @coral-xyz/anchor receives a total of 153,430 weekly downloads. As such, @coral-xyz/anchor popularity was classified as popular.
We found that @coral-xyz/anchor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.