Socket
Socket
Sign inDemoInstall

chialisp-preclsp

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chialisp-preclsp

precompile chialisp for simple development


Version published
Maintainers
1
Created

Readme

Source

chialisp-preclsp

描述
  • 使用nodejs驱动chialisp代码,让使用chialisp变得更加简单易用。
  • 这个驱动代码作为学习调试chialisp非常好用,但是不建议在工程项目中使用。
  • 感谢chia团队,让我看到了更加有趣的未来。
运行环境
  • 安装chia-dev-tools,然后进入虚拟环境进行使用。
安装
手动安装(推荐)
	#安装
	git clone git@gitee.com:woaianqi/chialisp-preclsp.git 
    cd chialisp-preclsp 
    npm link
    #更新
    git pull
npm安装(不推荐)
	#不推荐使用该方法 因为代码库更新较为频繁
	npm install chialisp-preclsp -g
运行指令
   #运行clsp源文件
   preclsp x.clsp
   #运行js驱动代码 (文件必须以#!clsp开头,才会进行编译)
   preclsp x.js
驱动代码演示
clsp源程序(train0.clsp)
(mod (
	MY_PUZZLE_HASH
	my_amount
	)

	(defconstant CREATE_COIN 51)

	(list
		(list CREATE_COIN MY_PUZZLE_HASH my_amount)
	)

)
clsp驱动代码(driver0.js)
#!clsp

/**
	一个简单的智能货币
	定义一个收款地址
	消费时指定金额即可
	消费金额大于部署金额,会报错
	小于部署金额,剩余的部分会被当作矿工费哦。
	当然你也可以在脚本调用npm的包
*/

//开启debug,当前目录下会生成日志信息供调试
DEBUG()

//设置测试金额
const amount = @XCH(0.0001)

//指定一个clsp源程序文件并curry一个参数
const curryPuzzle = Puzzle.of("train0.clsp").curry(@ph1)

//部署这个合约到主网 立即得到交易对象
const transaction = curryPuzzle.deploy(@fp1,amount)

//等待主网确认交易,获得交易的货币
const coin = await transaction.getCoin()

//设置解决方案 消费该货币
const spentMsg = coin.setSolution([amount]).doSpent()

//如果消费成功,拿到消费的货币
if(spentMsg.success){

	//等待主网确认 获取消费后的货币
	const [spendCoin] = await spentMsg.getSpendCoins()

	//打印该货币
	spendCoin.print()
}
运行
preclsp driver0.js
具体教程
  • 请移步chialisp-tutorials

FAQs

Last updated on 03 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc