美文网首页区块链大学区块链研习社
实操 decentraland 上传内容到土地

实操 decentraland 上传内容到土地

作者: 永远游泳的鱼 | 来源:发表于2018-09-27 07:18 被阅读35次

    实操 decentraland 上传内容到土地

    搞了一个上午,终于将内容上传到自己的土地上了,下面我把步骤给大家列一下。

    准备工作:DCL SDK 安装

    使用 npm install -g decentraland 一个命令即可安装完成。详情可以查看《安装指南》上的说明。

    新建一个 DCL 项目

    1. 新建一个项目

      mkdir demo
      cd demo
      dcl init
       ? Scene title:
       输入内容标题
       ? Your ethereum address:
       (optional, recommended -- used to check ownership of parcels when deploying your scene)
       输入拥有土地的以太地址
       ? Your name:
       (optional -- shown to other users so that they can contact you)
       输入名字
       ? Your email:
       (optional -- shown to other users so that they can contact you)
       邮箱
       ? Parcels comprising the scene
       (optional, recommended -- used to show the limts of your scene and upload to these coordinates)
       Please use this format: `x,y; x,y; x,y ...`
       输入拥有的土地地址
       ? Which scene template would you like to generate? Interactive
       ✔ Installing dependencies
      
       Success! Run 'dcl start' to see your scene
      
    2. 修改场景内容
      然后就可以根据自己的要求,通过修改 scene.tsx 文件,做到自定义的游戏或内容场景的开发。为了简单,我在自动生成的场景中,只加入一行欢迎标题,这样进入场景就能看到,如下在 scene.tsx 文件中加入 text 一行:

      return (
          <scene position={{ x: 5, y: 0, z: 5 }}>
          <entity rotation={doorRotation} transition={{ rotation: { duration: 1000, timing: 'ease-in' } }}>
            <box id="door" scale={{ x: 1, y: 2, z: 0.05 }} position={{ x: 0.5, y: 1, z: 0 }} color="#00FF00" />
          </entity>
          <box position={{ x: 2, y: 1, z: 0 }} scale={{ x: 2, y: 2, z: 0.05 }} color="#0000FF" />
          <text value="欢迎光临." hAlign="left" position={{ x: 1, y: 2 , z: -5 }} />
          <box position={{ x: -1, y: 1, z: 0 }} scale={{ x: 2, y: 2, z: 0.05 }} color="#0000FF" />
        </scene>
      )
      

      3D 模型可以从以下几个网站下载使用。

    1. 预览自己的场景

      dcl start
      

      会打开一个浏览器窗口,推荐使用 chrome 浏览器。
      可以使用 WASD 键上下左右行走,鼠标移动转向。

    2. 上传内容到自己的土地

      因为 dcl 上传的场景内容是保存在 ipfs 上的。所以为了上传场景内容,首先要开启 ipfs 本地服务。

      • 下载 ipfs

      • Mac OS X and Linux 下安装

         $ tar xvfz go-ipfs.tar.gz
         $ cd go-ipfs
         $ ./install.sh    
        
      • ipfs 配置

          ipfs init
        
      • 运行 ipfs 服务

         $ ipfs daemon
           Initializing daemon...
           Swarm listening on /ip4/127.0.0.1/tcp/4001
           Swarm listening on /ip4/192.168.36.188/tcp/4001
           Swarm listening on /ip6/::1/tcp/4001
           Swarm listening on /p2p-circuit/ipfs/QmTpjEfoRDEG8pzny3NmoRxyYR5eNs7Fknp1ayaCsHBBn8
           Swarm announcing /ip4/127.0.0.1/tcp/4001
           Swarm announcing /ip4/192.168.36.188/tcp/4001
           Swarm announcing /ip6/::1/tcp/4001
           API server listening on /ip4/127.0.0.1/tcp/5001
           Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
           Daemon is ready
        

    在浏览器中打开 http://localhost:5001/webui 可以查看 ipfs 网络连接情况。

    ipfs 服务开启后,就可以上传场景内容了,这一步只使用一个命令

    $ dcl deploy
    Tracked files:
    
     scene.js (443435 bytes)
     scene.json (490 bytes)
    
    ? You are about to upload 2 files (443925 bytes). Do you want to continue? Yes
    ✔ Uploading files to local IPFS node
    ✔ Checking IPNS for coordinates 36,-16
    ✔ Publishing IPNS for /ipfs/QmW43TKERbU8x1gwJBfuKabXw4etBhSptx4VDpMyM5a
    ℹ IPNS hash: QmVtpGyrBb3qbpfr6P8j71NYPnYryQgkRvh9K8h9DRW
    ✔ Pinning files to IPFS gateway
    
     Deployment complete!
    

    此命令主要有两个功能:一是上传场景文件到 IPFS。二是将场景文件的 IPNS 与 LAND 土地对应起来。

    在这里它会自动打开浏览器,然后在浏览器里中登录自己的 metamask,再点击 DEPLOY 发布。会弹出 metamask 的对话框。点击确认。等待以太网络确认交易。确认交易后上传即可完成。


    我自己在实际操作中,遇到两个问题:

    • 卡在确认交易这里很长时间,虽然 metamask 显示交易已经发送,但是 https://etherscan.io 上却查不到此笔交易。一直找不到问题,后来试着在 metamask 中自行发了两笔转帐,也是同新的问题,才意识到是 metamask 出了问题。最后在 metamask 中 reset 了帐户,然后再重试 dcl deploy 命令解决。

    • 确认交易后其操作中没有自动进行下去。我用 CTRL + C 中断了 dcl deploy 的运行,然后重新运行 dcl deploy 一下就行了。

    最终的效果,内测用户可以到我的土地地址上看一下,不是内测用户可以点击这个链接看一下:https://dcl-project-dshxwziwho.now.sh/?position=36%2C-17

    相关文章

      网友评论

        本文标题:实操 decentraland 上传内容到土地

        本文链接:https://www.haomeiwen.com/subject/nbusoftx.html