Git Product home page Git Product logo

web3-rs's Introduction

Web3 SDK for blockchain platforms

A pure Rust Web3 implementation for blockchain platforms.

Supported blockchain platforms

Solana

  • Branch: main
  • Status: Unstable
  • Progress: Rpc ndpoints are fully implemented

Near Protocol

  • Branch: near
  • Status: Unstable
  • Progress: Rpc ndpoints are partially implemented

web3-rs's People

Contributors

katopz avatar russellwmy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

web3-rs's Issues

GetTokenAccountsByOwnerResponse throw error

thread 'web3::connection::test_get_token_accounts_by_owner' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid type: map, expected byte array", line: 0, column: 0)', web3-rs/solana/src/rpc/token_accounts_by_owner.rs:126:49

Not sure that you got this working on your side? somehow I get panic while deserialize.
anyway I've to include TokenAccountsByOwnerResponseValue in mod otherwise I can't use to it.

use super::util::cluster::{cluster_api_url, Cluster};
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;
use web3_rs::core::{Provider, RcpClient};
use web3_rs::solana::rpc::*;

pub async fn get_token_accounts_by_owner(
    cluster: &Cluster,
    wallet_pubkey_str: &str,
    mint_pubkey_str: &str,
) -> Vec<TokenAccountsByOwnerResponseValue> {
    let wallet_pubkey = Pubkey::from_str(wallet_pubkey_str).unwrap();
    let mint_pubkey = Pubkey::from_str(mint_pubkey_str).unwrap();

    let api_url = cluster_api_url(cluster);
    let provider = Provider::new_http_provider(api_url.into());
    let client = RcpClient::new(provider);
    let request = GetTokenAccountsByOwnerRequest::new_mint(wallet_pubkey, mint_pubkey).into();

    match client.send(request).await {
        Ok(response) => {
            let result = GetTokenAccountsByOwnerResponse::from(response);
            log::info!("result:{:?}", result);
            let accounts = result.value.unwrap();
            log::info!("accounts:{:?}", accounts);

            accounts
        }
        Err(error) => {
            log::error!("{:?}", error);

            vec![]
        }
    }
}

#[cfg(test)]
#[tokio::test]
async fn test_get_token_accounts_by_owner() {
    let wallet_pubkey_str = "9K9RDUPvRfcVmHnoThUGkdR2bfQwa9oH1bs8RsmR2fjc";
    let mint_pubkey_str = "8YLbPb3TTEUL36gUyUiSx3ZffzaeqPoA1BkccyxTdn6i";

    let accounts: Vec<TokenAccountsByOwnerResponseValue> =
        get_token_accounts_by_owner(&Cluster::Devnet, wallet_pubkey_str, mint_pubkey_str).await;

    println!("accounts: {:?}", accounts);
    assert_ne!(Some(accounts).is_some(), true);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.