FISCO-BCOS平台,搭建第一个区块链应用

  • Post author:
  • Post category:其他

FISCO-BCOS平台

更新:
manjaro可以通过安装libxcrypt-compat来解决出现的libcrypt.so.1: cannot open shared object file: No such file or directory 问题。
以下是原文


记录搭建和使用中出现的问题。

搭建平台教程

教程非常详细,也非常清晰,只是会有一点点的坑点,记录一下。

环境

java

jdk 8-14,本人使用的是jdk11。

OS

本人使用的是Ubuntu20.04,建议使用Ubuntu,本来使用的是Manjaro,但是FISCO-BCOS的console启动会报错,所以最后不得不使用了Ubuntu。

manjaro在运行fisco bcos的控制台时,会报错,缺少关于netty的包,查了很多资料也没有解决掉,果断放弃。

坑点

FISCO-BCOS平台节点管理

官方教程在搭建时,会默认的搭建一个单机4节点的平台,但如果想要后期增加节点需要手动进行添加。

具体操作见教程

但按照教程中的步骤进行之后,会发现达成共识的节点仍然时4个,我是用WEBASE的前端查看发现的。

在仔细研究发现,其实新建节点属于是游离节点,应该手动加入到共识节点中。

所以在本地运行fisco的console,然后使用addSealer nodeid,其中nodeid为新建节点的id,来将新建节点加入到共识节点中。

gradle配置

在教程中的第三步

在这里插入图片描述

均使用了implentation,但在配置doLast时图中使用的均为已经被废弃的compileruntime
在这里插入图片描述

所以在配置之后,gradle运行出错,应该使用implementation而不是compile和runtime,如未修改,最终运行时,会出现加载不到主类的错误。

本人最终配置如下:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven {
        allowInsecureProtocol = true
        url "http://maven.aliyun.com/nexus/content/groups/public/"
    }
    maven {
        allowInsecureProtocol = true
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

def spring_version = "4.3.27.RELEASE"
List spring = [
        "org.springframework:spring-core:$spring_version",
        "org.springframework:spring-beans:$spring_version",
        "org.springframework:spring-context:$spring_version",
        "org.springframework:spring-tx:$spring_version",
]
dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:2.8.0')
    implementation spring
    implementation ('org.slf4j:slf4j-log4j12:1.7.25')//将compiple和runtime合并为implementation即可
}

test {
    useJUnitPlatform()
}

jar{
    destinationDir file('dist/apps')
    archiveName project.name + '.jar'
    exclude '**/*.xml'
    exclude '**/*.properties'
    exclude '**/*.crt'
    exclude '**/*.key'

    doLast {
        copy {
            from configurations.runtimeClasspath // 需要更改为runtimeClasspath
            into 'dist/lib'
        }
        copy {
            from file('src/test/resources/')
            into 'dist/conf'
        }
        copy {
            from file('tool/')
            into 'dist/'
        }
        copy {
            from file('src/test/resources/contract')
            into 'dist/contract'
        }
    }
}

版权声明:本文为qq_44639125原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。