前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >合约量化系统开发源码搭建(现成演示版)

合约量化系统开发源码搭建(现成演示版)

原创
作者头像
开发v_syn520110
发布2022-10-25 15:08:36
3680
发布2022-10-25 15:08:36
举报
文章被收录于专栏:MMMKA

Deployer API deployer对象提供了方法用于简化智能合约的部署。deployer.deploy(contract, args…, options)参数contract为使用artifacts.require引用的智能合约对象。参数args...为智能合约的构造函数的参数,用于初始化智能合约。参数options用于指定from,gas及overwrite等信息,overwrite用于重新部署某个已经完成部署的智能合约,默认的options参数在bottle.js文件中配置

例子:

代码语言:javascript
复制
// Deploy a single contract without constructor arguments
deployer.deploy(A);

// Deploy a single contract with constructor arguments
deployer.deploy(A, arg1, arg2, ...);

// Don't deploy this contract if it has already been deployed
deployer.deploy(A, {overwrite: false});

// Set a maximum amount of gas and `from` address for the deployment
deployer.deploy(A, {gas: 4612388, from: "0x...."});

// External dependency example:
//
// For this example, our dependency provides an address when we're deploying to the
// live network, but not for any other networks like testing and development.
// When we're deploying to the live network we want it to use that address, but in
// testing and development we need to deploy a version of our own. Instead of writing
// a bunch of conditionals, we can simply use the `overwrite` key.
deployer.deploy(SomeDependency, {overwrite: false});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
deployer.then(function() {…})

通过promise对象可以运行任意的部署步骤并调用指定的智能合约内部方法来进行交互

例子:

代码语言:javascript
复制
var ERC20 = artifacts.require("../contracts/Erc20.c")

module.exports = function (deployer, a) {
    deployer.deploy(ERC20, "1000000", "bitcoin", "BTC").then(function (instance) {
        deploy = instance;
        return deploy.GetTotalSupply()
    }).then(function (totalSupply) {
        console.log("totalSupply", totalSupply.toString());
        return deploy.GetDecimals();
    }).then(function (decimals) {
        console.log("decimals", decimals.toString());
        return deploy.GetTokenName();
    }).then(function (tokenName) {
        console.log("tokenName", tokenName);
        return deploy.GetAmount("0x122369f04f32269598789998de33e3d56e2c507a")
    }).then(function (balance) {
        console.log("balance", balance.toString());
    })
};

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档