Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@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.30.1] - 2024-06-20
RUSTUP_TOOLCHAIN
environment variable (#2941).AVM_HOME
environment variable (#2917).avm list
when GitHub API rate limits are reached (#2962)--no-install
option to the init
command (#2945).TryFromIntError
for Error
to be able to propagate integer conversion errors (#2950).upgrade
command (#2998).spl-associated-token-account
crate (#2999).declare_program!
(#2997).idl convert
command (#3009).idl type
command (#3017).anchor_lang::pubkey
macro for declaring Pubkey
const values (#3021).anchor-syn
dependency (#3030).const
of program ID to declare_id!
and declare_program!
(#3019).maxSupportedTransactionVersion
in AnchorProvider.send*()
methods (#2922).anchor init
(#2929).Cargo.lock
of the project when generating idls for external types (#2946).declare_program!
(#2959).declare_program!
(#2965).Vec<u8>
type with declare_program!
(#2966).ProgramError::ArithmeticOverflow
not found error (#2975).declare_program!
(#2967).declare_program!
(#2977).unexpected_cfgs
build warning (#2992).declare_program!
(#2994).rust-version
from crate manifests (#3000).address
constraint with field expressions (#3034).bytemuckunsafe
account serialization with declare_program!
(#3037).FAQs
Anchor client
The npm package @coral-xyz/anchor receives a total of 82,227 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.