首页
/ smoldot 开源项目教程

smoldot 开源项目教程

2024-08-31 19:02:05作者:申梦珏Efrain

项目介绍

smoldot 是一个 Substrate 和 Polkadot 链的替代客户端。它包含多个组件,包括 smoldot-light-js、smoldot-light 和 smoldot-full-node 等。smoldot 的主要目标是提供一个轻量级的客户端,能够在浏览器和 NodeJS/Deno 环境中运行。

项目快速启动

安装

首先,克隆项目仓库:

git clone https://github.com/smol-dot/smoldot.git
cd smoldot

构建

使用 Cargo 构建项目:

cargo build --release

运行

运行 smoldot 轻客户端:

cargo run --release --bin smoldot-light

应用案例和最佳实践

在浏览器中使用

smoldot-light-js 可以在浏览器中使用,以下是一个简单的示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>smoldot 示例</title>
    <script src="https://unpkg.com/smoldot@latest/dist/smoldot-light.js"></script>
</head>
<body>
    <script>
        const smoldot = require('smoldot');
        const client = smoldot.start({
            chainSpec: '...', // 链规范
            databaseContent: '...', // 数据库内容
        });
    </script>
</body>
</html>

在 NodeJS 中使用

在 NodeJS 中使用 smoldot:

const smoldot = require('smoldot');

const client = smoldot.start({
    chainSpec: '...', // 链规范
    databaseContent: '...', // 数据库内容
});

典型生态项目

smoldot-light-js

smoldot-light-js 是一个 JavaScript 包,可以在浏览器和 NodeJS/Deno 环境中连接到 Substrate 链作为轻客户端。

smoldot-light

smoldot-light 是一个平台无关的 Rust 库,可以连接到 Substrate 链作为轻客户端。

smoldot-full-node

smoldot-full-node 是一个正在开发中的全节点原型,可以连接到 Substrate 链。

通过这些组件,smoldot 提供了一个全面的解决方案,适用于各种不同的应用场景。

登录后查看全文
热门项目推荐