The protocol are designed and made for the future of cross-IP, cross-chain metaverse.

Overview

Avatar-protocol 化身协议

This project demonstrates how to use the Solana Javascript API to interact with programs on the Solana blockchain.

The project comprises of:

  • An on-chain program derived on Metaplex's metadata.
  • A client that can send a "hello" to an account and get back the number of times "hello" has been sent

Translations

Table of Contents

Quick Start

Open in Gitpod

If you decide to open in Gitpod then refer to README-gitpod.md, otherwise continue reading.

The following dependencies are required to build and run this example, depending on your OS, they may already be installed:

If this is your first time using Rust, these Installation Notes might be helpful.

Configure CLI

If you're on Windows, it is recommended to use WSL to run these commands

  1. Set CLI config url to localhost cluster
$ solana config set --url localhost
  1. Create CLI Keypair

If this is your first time using the Solana CLI, you will need to generate a new keypair:

$ solana-keygen new

Start local Solana cluster

This example connects to a local Solana cluster by default.

Start a local Solana cluster:

$ solana-test-validator

Note: You may need to do some system tuning (and restart your computer) to get the validator to run

Listen to transaction logs:

$ solana logs

Install npm dependencies

$ npm install

Build the on-chain program

There is both a Rust and C version of the on-chain program, whichever is built last will be the one used when running the example.

$ npm run build:program-rust
$ npm run build:program-c

Deploy the on-chain program

$ solana program deploy dist/program/helloworld.so

Run the JavaScript client

$ npm run start

Expected output

Public key values will differ:

Let's say hello to a Solana account...
Connection to cluster established: http://localhost:8899 { 'feature-set': 2045430982, 'solana-core': '1.7.8' }
Using account AiT1QgeYaK86Lf9kudqKthQPCWwpG8vFA1bAAioBoF4X containing 0.00141872 SOL to pay for fees
Using program Dro9uk45fxMcKWGb1eWALujbTssh6DW8mb4x8x3Eq5h6
Creating account 8MBmHtJvxpKdYhdw6yPpedp6X6y2U9dCpdYaZJdmwV3A to say hello to
Saying hello to 8MBmHtJvxpKdYhdw6yPpedp6X6y2U9dCpdYaZJdmwV3A
8MBmHtJvxpKdYhdw6yPpedp6X6y2U9dCpdYaZJdmwV3A has been greeted 1 times
Success

Not seeing the expected output?

  • Ensure you've started the local cluster, built the on-chain program and deployed the program to the cluster.
  • Inspect the program logs by running solana logs to see why the program failed.
    • Transaction executed in slot 5621:
      Signature: 4pya5iyvNfAZj9sVWHzByrxdKB84uA5sCxLceBwr9UyuETX2QwnKg56MgBKWSM4breVRzHmpb1EZQXFPPmJnEtsJ
      Status: Error processing Instruction 0: Program failed to complete
      Log Messages:
        Program G5bbS1ipWzqQhekkiCLn6u7Y1jJdnGK85ceSYLx2kKbA invoke [1]
        Program log: Hello World Rust program entrypoint
        Program G5bbS1ipWzqQhekkiCLn6u7Y1jJdnGK85ceSYLx2kKbA consumed 200000 of 200000 compute units
        Program failed to complete: exceeded maximum number of instructions allowed (200000) at instruction #334
        Program G5bbS1ipWzqQhekkiCLn6u7Y1jJdnGK85ceSYLx2kKbA failed: Program failed to complete
      

Customizing the Program

To customize the example, make changes to the files under /src. If you change any files under /src/program-rust or /src/program-c you will need to rebuild the on-chain program and redeploy the program.

Now when you rerun npm run start, you should see the results of your changes.

Learn about Solana

More information about how Solana works is available in the Solana documentation and all the source code is available on github

Further questions? Visit us on Discord

Learn about the client

The client in this example is written in TypeScript using:

Entrypoint

The client's entrypoint does five things.

Establish a connection to the cluster

The client establishes a connection with the cluster by calling establishConnection.

Establish an account to pay for transactions

The client ensures there is an account available to pay for transactions, and creates one if there is not, by calling establishPayer.

Check if the helloworld on-chain program has been deployed

In checkProgram, the client loads the keypair of the deployed program from ./dist/program/helloworld-keypair.json and uses the public key for the keypair to fetch the program account. If the program doesn't exist, the client halts with an error. If the program does exist, it will create a new account with the program assigned as its owner to store program state (number of hello's processed).

Send a "Hello" transaction to the on-chain program

The client then constructs and sends a "Hello" transaction to the program by calling sayHello. The transaction contains a single very simple instruction that primarily carries the public key of the helloworld program account to call and the "greeter" account to which the client wishes to say "Hello" to.

Query the Solana account used in the "Hello" transaction

Each time the client says "Hello" to an account, the program increments a numerical count in the "greeter" account's data. The client queries the "greeter" account's data to discover the current number of times the account has been greeted by calling reportGreetings.

Learn about the on-chain program

The on-chain helloworld program is a Rust program compiled to Berkley Packet Format (BPF) and stored as an Executable and Linkable Format (ELF) shared object.

The program is written using:

Programming on Solana

To learn more about Solana programming model refer to the Programming Model Overview.

To learn more about developing programs on Solana refer to the On-Chain Programs Overview

Pointing to a public Solana cluster

Solana maintains three public clusters:

  • devnet - Development cluster with airdrops enabled
  • testnet - Tour De Sol test cluster without airdrops enabled
  • mainnet-beta - Main cluster

Use the Solana CLI to configure which cluster to connect to.

To point to devnet:

$ solana config set --url devnet

To point back to the local cluster:

$ solana config set --url localhost

Expand your skills with advanced examples

There is lots more to learn; The following examples demonstrate more advanced features like custom errors, advanced account handling, suggestions for data serialization, benchmarking, etc...

You might also like...
ARYA Network is a polkadot/substrate based chain for Non-fungible Token platform on which we can own sell and buy the NFT's on polkadot network.

ARYA Network ARYA Network is a polkadot/substrate based chain for Non-fungible Token platform on which we can own sell and buy the NFT's on polkadot n

Automatically assess and score software repositories for supply chain risk.

Hipcheck Hipcheck scores risks for software projects; yours and your dependencies. It analyzes repositories to assess risks, review development practi

CLI tool for deterministically building and verifying executable against on-chain programs or buffer accounts

Solana Verify CLI A command line tool to build and verify solana programs. Users can ensure that the hash of the on-chain program matches the hash of

`llm-chain` is a powerful rust crate for building chains in large language models allowing you to summarise text and complete complex tasks

llm-chain 🚀 llm-chain is a collection of Rust crates designed to help you work with Large Language Models (LLMs) more effectively. Our primary focus

Secure your on-chain approvals and sleep with ease.
Secure your on-chain approvals and sleep with ease.

🇹🇷 Eth Global Istanbul 2023 Hackaton Project 🇹🇷 Table of Contents Table of Contents About The Project Built With Getting Started Installation Cont

Authenticate the cryptographic chain-of-custody of Linux distributions (like Arch Linux and Debian) to their source code inputs

backseat-signed Authenticate the cryptographic chain-of-custody of Linux distributions (like Arch Linux and Debian) to their source code inputs. This

A tool for quickly collecting function selectors and decoding signatures from on-chain EVM bytecode.
A tool for quickly collecting function selectors and decoding signatures from on-chain EVM bytecode.

Overview | Disclaimer | Tests | Installation | Usage | Examples | Aknowledgements | License Overview Sigmund provides a CLI that allows users to colle

LayerCake: An insured-in-transit cross-network composability protocol

LayerCake: An insured-in-transit cross-network composability protocol The key features of LayerCake are: Instant transfers as opposed to the delayed t

Official implementation of the YeeCo Root Chain (Layer 1)
Official implementation of the YeeCo Root Chain (Layer 1)

yeeroot Official implementation of the YeeCo Root Chain (Layer 1) YeeCo is a permissionless, secure, high performance and scalable public blockchain p

Owner
Wind-protocol
This is the main github of the Wind-Ecosystem.
Wind-protocol
Basilisk node - cross-chain liquidity protocol built on Substrate

Basilisk node Local Development Follow these steps to prepare a local Substrate development environment ??️ Simple Setup Install all the required depe

Galactic Council 52 Dec 27, 2022
An open source desktop wallet for nano and banano with end-to-end encrypted, on chain messaging using the dagchat protocol.

An open source wallet with end-to-end encrypted, on chain messaging for nano and banano using the dagchat protocol.

derfarctor 22 Nov 6, 2022
Built for Perpetual Protocol v2 Curie on Optimism chain. This CLI tool was built with Rust.

Perpetual Protocol CLI for Perp v2 Curie This tool is to provide a simple, fast and efficient way to interact Perpetual Protocol contracts from your t

Brendan Wenzel 4 Jan 11, 2023
A crate for working with Ethereum beacon chain light client protocol messages. `no_std` friendly!

eth-lightclient-rs A crate for working with Ethereum beacon chain light client protocol messages. no_std friendly! !! For hacking and experimentation

Willem Olding 12 Jan 6, 2023
Cross-chain hub for Crypto Asset on Polkadot

ChainX ChainX is a community-driven project built on the next-generation blockchain framework substrate, the largest Layer-2 network of Bitcoin using

ChainX 261 Dec 28, 2022
Cross-chain bridge message delivery network. We are hiring, [email protected]

Introduction Implementation of a https://darwinia.network node in Rust based on the Substrate framework. This repository contains runtimes for the Dar

Darwinia Network 225 Nov 8, 2022
a cross-chain dollar cost averaging

Ethtent an intent-solver infrastructure prototype for automated defi earning Demo Video here Project Desciption We build an intent-solver infrastructu

null 4 Sep 11, 2023
Voice over the BitcoinSV protocol (made for CoinGeek 2021)

The BitcoinPhone Voice over the Bitcoin protocol. Setup Instructions for Mac Install rust https://www.rust-lang.org/tools/install Install homebrew htt

Joe 15 Mar 12, 2022
Making composability with the Zeta DEX a breeze, FuZe provides CPI interfaces and sample implementations for on-chain program integration.

Zeta FuZe ?? Zeta FuZe FuZe is Zeta's cross-program integration ecosystem. This repository contains the Zeta Cross Program Invocation (CPI) interface

Zeta 39 Aug 27, 2022
A very bare-bone Block Chain demo that purely implemented by Rust and yew

Intro bloc is one of bare-bone blockchain demo written by Rust, Yew during my learning BlockChain, about years ago. see demo here It just demonstrate

null 4 Dec 16, 2022