Compilation and compilation of Changan chain GO language smart contract

pull image

docker pull chainmakerofficial/chainmaker-docker-go-contract:v2.2.1

Create a working directory $WORK_DIR

For example, /data/workspace/contract is mounted to the docker container to facilitate subsequent necessary file copies.

mkdir -p /data/workspace/contract

Start the container

$ docker run -it --name chainmaker-docker-go-contract -v /data/workspace/contract:/home chainmakerofficial/chainmaker-docker-go-contract:v2.2.1 bash

After starting the container, it will automatically enter the root directory of the container.

copy template

There is a smart contract template in go language in the /data directory of the container, which will be copied to the /home directory (meaning that it is also copied to the host’s mounted /data/workspace/contract directory)

# cd /data/
# ls
admin1.sign.crt  contract_docker_go_template.tar.gz
# cp contract_docker_go_template.tar.gz /home

Then copy the contract_docker_go_template.tar.gz in the server /data/workspace/contract directory to the computer where the smart contract is developed, and unzip it to get a smart contract development demo project of contract_docker_go. Or download the official contract-sdk-docker-go project.

Sign in · ChainMaker welcomes the Changan Chain open source platform https://git.chainmaker.org.cn/chainmaker/contract-sdk-docker-go

write contract

In the contract project of contract_docker_go, the main thing that needs to be modified is main.go. Rewrite or modify main.go according to your own smart contract development needs.

Compile and compress the contract

First copy the written contract_docker_go project source file back to the server /data/workspace/contract, and then enter the chainmaker-docker-go-contract container again, and the corresponding container directory is /home/contract_docker_go

$ cd /home
$ cd contract_docker_go
$ ./build.sh
please input contract name, contract name should be same as name in tx: 
<contract_name> #此处contract_name必须和交易中的合约名一致
please input zip file: 
<zip_file_name> #建议与contract_name保持一致(不用加文件后缀)
...

The location of the compiled and compressed files is in .

/home/contract_docker_go/<contract_name>.7z

After success, you can copy the <contract_name>.7z compressed package to the Changan chain node environment and use the cmc command to deploy it, or use the sdk to create a smart contract. For specific methods, please refer to another blog Chang’an chain GO language smart contract environment construction and use http://t.csdn.cn/8DNaN

Guess you like

Origin blog.csdn.net/h363659487/article/details/125420782