# Dyson协议测试网

By [hao](https://paragraph.com/@ethnbb) · 2022-09-19

---

**什么是戴森协议？**

简而言之，Dyson 协议的创建考虑了开发人员。关键思想是创建一个能够运行简单脚本的安全区块链，其中_表示和界面都是完全分布式的并内置在协议_中。换句话说：_一切都在链上。_

Dyson 区块链上的脚本在 Python 的简单子集（称为 Dyslang）和[HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview)（特别是[WSGI 协议](https://www.fullstackpython.com/wsgi-servers.html)）上运行，因此您可以使用您已经熟悉的工具编写完全分布式的应用程序或网站。

在底层，Dyson 协议使用[Cosmos SDK](https://docs.cosmos.network/)及其[跨链通信协议](https://docs.cosmos.network/master/ibc/overview.html)，因此它与 Cosmos 生态系统完全互操作。

我们有很多令人兴奋的项目，我们将在此过程中寻找明星开发人员、beta 测试人员和验证人员。我们这个项目的主要目标之一是奖励早期采用者和开发人员，所以我们希望您能加入我们！包括对早期采用者/测试者的奖励！

官方推特：[https://twitter.com/DysonProtocol](https://twitter.com/DysonProtocol)

官方教程：[https://medium.com/@dysonprotocol](https://medium.com/@dysonprotocol)

正文:
---

首先打开测试网[https://dys.dysonvalidator.com/](https://dys.dysonvalidator.com/)连接KepIr钱包，点击批准会自动添加Dyson链

![](https://storage.googleapis.com/papyrus_images/b31023822c93109b2f4b669179d82cffe88b4c535d1e4ad6f06a5e54ec9bea4a.png)

### 然后复制钱包地址去DC [https://discord.gg/87rwhNJA](https://discord.gg/87rwhNJA) 的testnet-airdrop频道领水，一分钟左右就到账了

接下来开始测试:

### 一：如何制作您的第一个基本 Dyson 协议功能

1，单击您的脚本按钮

![](https://storage.googleapis.com/papyrus_images/5b6207ccd7865147dfc0481f7d975bab04489b2ea9f8391677e36bfdf5d8ec0a.png)

2：在编辑器中输入以下函数，然后点击save保存后钱包批准

    def my_function():
        print('hello world')
        return 123
    

![](https://storage.googleapis.com/papyrus_images/45517f078f0c05275c2e15f10675674c3713c6816c5f42e7fc1294b5d4b01d76.png)

![](https://storage.googleapis.com/papyrus_images/0d0457e13709ec038fb8c5c2f62ff1b01d444fdcd4a500073224b226d5adeb5c.png)

3: 点击Query my\_function

![](https://storage.googleapis.com/papyrus_images/f3bffed461ae6fac3bd00420a5d0cfe8f10a8f088c36d8255857ee8c6efcdad7.png)

4：再点击Run my\_function然后钱包批准

![](https://storage.googleapis.com/papyrus_images/0c1e11b130f22d58c4d8975aab268aaf787e7519daf80702e477197cbe8ea10a.png)

### 二：如何在 Dyson 协议上更新函数和接受参数

1: 把之前的代码替换成以下代码，点击save保存钱包批准，然后my\_name框里输入你要的名字，点击 Query say\_hello，下面会显示出你的名字

    def say_hello(my_name: str):
        print('hello '+ my_name) 
        return 123
    

![](https://storage.googleapis.com/papyrus_images/61f4c55709bd44101bdc4aab4f85226dfabddbeef517b891c4564b6c173fba36.png)

### 三：如何在戴森协议上保存到存储

1：步骤如图，第二步是输入dyson，第四步是你的钱包地址，第五步是钱包地址后面加/my\_greeting 第六步是输入this is a test

![](https://storage.googleapis.com/papyrus_images/fcb2bdc7be23dbc0e1a8c7392715535912fdd1680fce3dad0e50b2abfc97f1b0.png)

2：重新开一个测试网页，步骤如图，搜索“dyson”，第四步是你的地址加/my\_greeting

第五步的运行结果和你填写的一致就对了

![](https://storage.googleapis.com/papyrus_images/13118b50cebe94f602654c49f83c4f9be1d6a3b8b396a1d51b20a50561d1e208.png)

3: 点击最上方你的地址打开编辑器，把原来的代码替换成以下代码，然后保存，钱包批准，第六步显示的名字是你取的就对了！然后重复上图步骤检验一下，你会发现运行结果变成了你的钱包地址和名字就对了

    from dys import _chain, get_script_address
    def say_hello(my_name: str):
        data = "hello " + my_name
        print(data) # to help debug
        return _chain(
            "dyson/sendMsgCreateStorage",
            creator=get_script_address(),
            index=get_script_address() + "/my_greeting",
            data=data,
            force=True,
        )
    

![](https://storage.googleapis.com/papyrus_images/0f866e395949bd025c1904015f6390a238eeaa5431cffaeed2ab6930b2e18344.png)

### 四：如何在 Dyson 协议上读取存储和渲染网站

1：将第1行代码替换成以下第一个代码，然后在第4行下面添加另一个代码，保存，批准

    from dys import _chain, get_script_address, get_caller
    
    assert get_script_address() == get_caller(), "permission denied"
    

![](https://storage.googleapis.com/papyrus_images/8ad8c1546adc29991d70bfde2ad13b153627d14082f8e9805d6fc73abc6a40d4.png)

2：在代码末尾留两行，然后添加以下代码，保存，批准，左侧会多出来一个命令框，步骤如图

    def get_greeting(): 
        return _chain( 
            "dyson/QueryStorage", 
            index=get_script_address() + "/my_greeting", 
        )
    

![](https://storage.googleapis.com/papyrus_images/37d319fec5e5a49e316460cb26411447397d82d2568d93ec8c0910bc038cd221.png)

3：再次代码末行留两行，添加以下代码，保存，批准，然后用这个网址新开个网页

https://你的钱包地址.dysonvalidator.com 如图显示

    def application(environ, start_response): 
        start_response("200 ok", [("Content-type", "text/plain")]) 
        return ["Test WSGI website says: hello world".encode()]
    

![](https://storage.googleapis.com/papyrus_images/3f2cada4956895673658e3ae443a8f8adb05796dce3a35b114801b533f4b5f03.png)

4：将最后一行代码替换成以下代码，保存，批准，然后刷新你的那个网站，会变成你的名字

    greeting_data = get_greeting()["result"]["storage"]["data"] 
        return [greeting_data.encode()]
    

![](https://storage.googleapis.com/papyrus_images/0b6ac9320fd2bb36e245075f983caf42cbf1f525a1f0ac258fa1b739fae371bf.png)

### 五：如何在 Dyson 协议上使用 HTML 和 CSS 更改网站的外观

1：将代码全部替换成以下代码，保存，批准，然后点击左侧的Query render\_page按钮，然后刷新你的网站，会发现多了一层颜色就对了！如图

最后这步要添加很多代码，麻烦，我直接用了完整代码了，想看的可以去看官方教程

    import html
    from string import Template
    from dys import _chain, get_script_address, get_caller
    def say_hello(my_name: str):
        assert get_script_address() == get_caller(), "permission denied"
        data = "hello " + my_name
        print(data)  # to help debug
        return _chain(
            "dyson/sendMsgCreateStorage",
            creator=get_script_address(),
            index=get_script_address() + "/my_greeting",
            data=data,
            force=True,
        )
    def get_greeting():
        return _chain(
            "dyson/QueryStorage",
            index=get_script_address() + "/my_greeting",
        )
    def render_page(body:str):
        return Template(
            """<!doctype html>
        <html>
            <head>
                <title>Hello World</title>
                <meta charset=utf-8>
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
                <style>
                    .heading {
                        text-shadow: #FC0 1px 0 10px;
                    }
                </style>
            </head>
            <body>
                <div class="container">
                    <h1 class="heading">Greeting!</h1>
                    <p>$body</p>
                </div>
            </body>
        </html>
        """
        ).safe_substitute(body=body)
    def application(environ, start_response):
        start_response("200 ok", [("Content-type", "text/html")])
        greeting_data = get_greeting()["result"]["storage"]["data"]
        return [
            render_page(html.escape(greeting_data)).encode(),
        ]
    

![](https://storage.googleapis.com/papyrus_images/509a9a143a90f0eb31cb14119e7fd2df2d8d11fbf9c6c107715ec8961e538afa.png)

![](https://storage.googleapis.com/papyrus_images/163f1a4e5af33981a2b4ec9209447322097ca08d59485788e67305733e920954.png)

![](https://storage.googleapis.com/papyrus_images/1e669e1a4a926ee19f2fad87cb4c4976ff9982751c8dc701f2d7c0e146ac7c87.png)

### 六：如何循环存储以呈现有关戴森协议的博客

1：把原来的代码全部替换成以下代码，保存，批准

    import re2
    import html
    from string import Template
    from dys import _chain, get_script_address, get_caller
    
    
    def new_post(title: str, body: str):
        assert get_script_address() == get_caller(), "permission denied"
        data = f"{title} -- {body}"
        title_slug = re2.sub("\W+", "-", title)
        print(data)  # to help debug
        return _chain(
            "dyson/sendMsgCreateStorage",
            creator=get_script_address(),
            index=get_script_address() + "/post/v1/" + title_slug,
            data=data,
            force=True,
        )
    
    
    def get_all_posts():
        response = _chain(
            "dyson/QueryPrefixStorage", 
            prefix=get_script_address() + "/post/v1/"
        )
        return response["result"]
    
    
    def render_page(body: str):
        return Template(
            """<!doctype html>
        <html>
            <head>
                <title>Hello World</title>
                <meta charset=utf-8>
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
                <style>
                    .heading {
                        text-shadow: #FC0 1px 0 10px;
                    }
                </style>
            </head>
            <body>
                <div class="container">
                    <h1 class="heading">Posts!</h1>
                    <p>$body</p>
                </div>
            </body>
        </html>
        """
        ).safe_substitute(body=body)
    
    
    def render_posts(posts: list[dict[str, str]]):
        return (
            "<ul>"
            + "".join(["<li>" + html.escape(s["data"]) + "</li>" for s in posts])
            + "</ul>"
        )
    
    
    def application(environ, start_response):
        start_response("200 ok", [("Content-type", "text/html")])
        post_data = get_all_posts()
        return [
            render_page(render_posts(post_data["storage"])).encode(),
        ]
    

2：步骤如图，你想要写多篇文章就重复图中123步就可以了

![](https://storage.googleapis.com/papyrus_images/9cc0b1561c4753bc8480ecf63580dfe195943b28ea5feb71306ba24934133658.png)

3：这样的就可以了！可以看出我是写了3篇文章

![](https://storage.googleapis.com/papyrus_images/bca64815a5a2b631ba5ff9e90c2cf9bb0725b5bd21eb6cb0bd3be0624a6b3bd9.png)

到这里就暂时结束了，后面还有后续步骤，官方教程还没出，出了再写后续

作者推特：[https://twitter.com/qazplm456456](https://twitter.com/qazplm456456)

---

*Originally published on [hao](https://paragraph.com/@ethnbb/dyson)*
