Anchor is a framework for Solana's Sealevel runtime providing several convenient developer tools

Anchor is a framework for Solana's IDL specification

Anchor

Solana Sealevel Framework

Anchor is a framework for Solana's Sealevel runtime providing several convenient developer tools for writing smart contracts.

  • Rust eDSL for writing Solana programs
  • IDL specification
  • TypeScript package for generating clients from IDL
  • CLI and workspace management for developing complete applications

If you're familiar with developing in Ethereum's Solidity, Truffle, web3.js, then the experience will be familiar. Although the DSL syntax and semantics are targeted at Solana, the high level flow of writing RPC request handlers, emitting an IDL, and generating clients from IDL is the same.

Getting Started

For a quickstart guide and in depth tutorials, see the anchor book and the older documentation that is being phased out. To jump straight to examples, go here. For the latest Rust and TypeScript API documentation, see docs.rs and the typedoc.

Packages

Package Description Version Docs
anchor-lang Rust primitives for writing programs on Solana
anchor-spl CPI clients for SPL programs on Solana
anchor-client Rust client for Anchor programs
@project-serum/anchor TypeScript client for Anchor programs
@project-serum/anchor-cli CLI to support building and managing an Anchor workspace

Note

  • Anchor is in active development, so all APIs are subject to change.
  • This code is unaudited. Use at your own risk.

Examples

Here's a counter program, where only the designated authority can increment the count.

For more, see the examples and tests directories.

License

Anchor is licensed under Apache 2.0.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Anchor by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Contribution

Thank you for your interest in contributing to Anchor! Please see the CONTRIBUTING.md to learn how.

Thanks ❤️

Issues

Collection of the latest Issues

blockiosaurus

blockiosaurus

2

When making a CPI call with an UncheckedAccount as signer, the is_signer field doesn't carry through the CPI and so the invoked instruction has no signer.

The current functioning workaround is to replace the CPI call with an invoke and manually copying the is_signer field to the passed-in account metas.

cavemanloverboy

cavemanloverboy

3

As @thesoftwarejedi pointed out, presently the overflow-checks = true does nothing. It must be at the root Cargo.toml. I will submit a PR this AM with the fix and more details about tests for this feature.

rayniel95

rayniel95

0

Actually is mandatory to have one enum with all the custom errors defined on it. If the contract have multiple errors is a head pain to read the code and understand the context of the errors.

Problem: If I try to add another custom error, with an enum, the parser do not included it in the idl. Let's see a modified version of the example in the doc

The generated idl is:

The second error is not added to the idl and it can not be recognized as an error. Suggestion: allow to add custom errors in multiple enums to improve readability.

bcerecer

bcerecer

1

⚠️ Don't use issues for support questions ("How does x feature work in Anchor? How to do x in Anchor?"). Use the discord instead https://discord.gg/GVRw4kHB (but don't ping maintainers). ⚠️ Currently, examples use deprecated methods such as https://github.com/project-serum/anchor/blob/master/examples/tutorial/basic-0/tests/basic-0.js#L13 which should be updated to use methods instead as mentioned here: https://github.com/project-serum/anchor/blame/master/CHANGELOG.md#L107

sohrab-

sohrab-

1

Programs fail to compile when including Accounts structs from other modules than main lib. Not sure if this is a bug or feature. I asked on Discord but no one replied. Common use cases would be sane reuse or creating composite Accounts structs from other programs, etc.

To replicate this, simply move one of the composite Accounts in tests/composite to another module, as I have done here: https://github.com/sohrab-/anchor/commit/6bb995fafb724b2e03f2a35db094247baae99b57. This results in below compilation error.

sadeghte

sadeghte

0

This is the error that I faced:

IdlError: Type not found: {"name":"ethAddress","type":{"defined":"u256"}}
at Function.fieldLayout (/home/***********/node_modules/ts:94:19)
at /home/***********/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:114:22
at Array.map (<anonymous>)
at /home/***********/node_modules/@project-serum/anchor/src/coder/borsh/instruction.ts:113:38
at Array.map (<anonymous>)
at Function.parseIxLayout (/home/***********/node_modules/ts:112:26)
at new BorshInstructionCoder (/home/***********/node_modules/ts:47:43)
at new BorshCoder (/home/***********/node_modules/ts:39:24)
at new Program (/home/***********/node_modules/ts:282:28)
at /home/***********/cli/muon.ts:30:15

lib.rs

types.rs

instructions.rs

state.rs

idl.json

ngundotra

ngundotra

7

Problem:

Excess demand for writing to program accounts incentivizes transaction spamming. This transfers economic demand away from highly requested dApp/program usage to excessive demand for network bandwidth.

Historically, bandwidth demand from bots has incurred so much network traffic that Solana consensus is forced to restart. Examples of this:

Fix

Metaplex recently introduced a botting fee that will charge bots for incorrect transactions, rather than failing the transaction.

Pros:

  • This appears to have stabilized bot spam that previously forced Solana consensus to restart
  • Metaplex directs these funds collected from bots to NFT creators via their candy machine account

Cons:

  • Front-end developers have to work harder to prevent human users from getting charged bot fees
  • Bots lose money

Request:

Allow new program developers to specify the conditions under which they charge bots, and enable a toggle to turn these fees on and off.

In practice, this could look something like the following:

Welcome to all feedback on this. I do not believe all of this functionality should live in Anchor, but I do believe this is the right place to start the discussion.

developdeez

developdeez

2

Keep getting this error when testing the base model. Is initialized!: Error: failed to get recent blockhash: FetchError: request to http://localhost:8899/ failed, reason: connect ECONNREFUSED ::1:8899

I've tried while running validator locally and not. It doesn't work. Is there a fix coming?

asktree

asktree

3

If I make an #[account] struct called RNGEvent, and then use program.account to fetch it, I get an invalid account discriminator error. If I rename the struct to Cum or RngEvent it works fine.

I am guessing this is to do with the consecutive capital letters in "RNGEvent" though I have not tested this.

This issue appears both in anchor-ts and anchor-client-gen.

bonedaddy

bonedaddy

0

Overview

At present there is no way to perform zero copy deserialization that does not allow bypassing owner and/or discriminator checks, which forces people to using the try_deserialize and try_deserialize_unchecked methods which do not do zero copy deserialization, which will cause stack size issues.

All available functions perform a combination of (or just one of) the owner and discriminator checks. I've listed a few solutions below:

  • Fix https://github.com/project-serum/anchor/issues/1857
  • Add a function like try_from_unsafe that loads the account by bypassing owner check, but enforcing discriminator check
  • Add a function like try_from_danger that loads the account by bypassing owner and discriminator check

Realistically though the simplest solution (literally 1 key word added to a PR and the feature is released) is to make the AccountLoader::new function public. That aside I think actual unsafe loading of the accounts should be made possible without having to do any crazy things like mocking program structure implementation etc..

Versions

Find the latest versions by id

v0.24.2 - Apr 13, 2022

For a list of changes in this release, see the Change Log.

v0.24.1 - Apr 12, 2022

For a list of changes in this release, see the Change Log.

v0.24.0 - Apr 12, 2022

For a list of changes in this release, see the Change Log.

v0.23.0 - Mar 21, 2022

For a list of changes in this release, see the Change Log.

v0.22.1 - Feb 28, 2022

For a list of changes in this release, see the Change Log.

v0.22.0 - Feb 21, 2022

For a list of changes in this release, see the Change Log.

v0.21.0 - Feb 08, 2022

For a list of changes in this release, see the Change Log.

v0.20.1 - Jan 09, 2022

For a list of changes in this release, see the Change Log.

v0.20.0 - Jan 06, 2022

For a list of changes in this release, see the Change Log.

v0.19.0 - Dec 08, 2021

For a list of changes in this release, see the Change Log.

v0.18.2 - Nov 14, 2021

For a list of changes in this release, see the Change Log.

v0.18.0 - Oct 25, 2021

For a list of changes in this release, see the Change Log.

v0.17.0 - Oct 03, 2021

For a list of changes in this release, see the Change Log.

v0.16.2 - Sep 27, 2021

For a list of changes in this release, see the Change Log.

v0.16.1 - Sep 17, 2021

For a list of changes in this release, see the Change Log.

v0.16.0 - Sep 17, 2021

For a list of changes in this release, see the Change Log.

v0.15.0 - Sep 08, 2021

For a list of changes in this release, see the Change Log.

v0.14.0 - Sep 02, 2021

For a list of changes in this release, see the Change Log.

v0.13.2 - Aug 11, 2021

For a list of changes in this release, see the Change Log.

v0.13.1 - Aug 11, 2021

For a list of changes in this release, see the Change Log.

v0.13.0 - Aug 09, 2021

For a list of changes in this release, see the Change Log.

v0.12.0 - Aug 04, 2021

For a list of changes in this release, see the Change Log.

v0.11.1 - Jul 10, 2021

For a list of changes in this release, see the Change Log.

v0.11.0 - Jul 03, 2021

For a list of changes in this release, see the Change Log.

v0.10.0 - Jun 28, 2021

For a list of changes in this release, see the Change Log.

v0.9.0 - Jun 16, 2021

For a list of changes in this release, see the Change Log.

v0.8.0 - Jun 11, 2021

For a list of changes in this release, see the Change Log.

v0.7.0 - May 31, 2021

For a list of changes in this release, see the Change Log.

v0.6.0 - May 23, 2021

For a list of changes in this release, see the Change Log.

v0.5.0 - May 07, 2021

For a list of changes in this release, see the Change Log.

Information - Updated May 19, 2022

Stars: 2.0K
Forks: 737
Issues: 456

Wagyu Etherum blockchain ledger and wallet in Rust

Cross platform ether wallet generator that makes automated creation of crypto wallets easy

Wagyu Etherum blockchain ledger and wallet in Rust

Reference implementation of the Stacks blockchain in Rust

Reference implementation of the Proof of Transfer (PoX) mining that anchors to Bitcoin security

Reference implementation of the Stacks blockchain in Rust

This repository contains core Rust and Haskell libraries used by various

components of the Concordium blockchain, as well as some tools used for testing

This repository contains core Rust and Haskell libraries used by various

Blockchain Commons torgap-sig-cli-rust

torgap-sig-cli-rust is a fork of Minisign, with support for

Blockchain Commons torgap-sig-cli-rust

A Blockchain implementation in Rust

MIT (c) Doublify Technologies

A Blockchain implementation in Rust

Diem core repo for Rust

Diem is a user focused blockchain application, that has increased in popularity significantly in the crypto / blockchain space

Diem core repo for Rust

Rust implementation of the Inter-Blockchain Communication (IBC) protocol

This project comprises primarily four crates:

Rust implementation of the Inter-Blockchain Communication (IBC) protocol

A simple blockchain example written in Rust:

Defines data structures to model a minimum blockchain

A simple blockchain example written in Rust:

A Blockchain implementation in pure Rust

Below find an example usage of the library:

A Blockchain implementation in pure Rust
Facebook Instagram Twitter GitHub Dribbble
Privacy