首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3_deploy_contracts.js问题

3_deploy_contracts.js问题
EN

Ethereum用户
提问于 2018-08-20 03:00:01
回答 1查看 194关注 0票数 3

解决我的部署问题的好方法是什么:(推进问题:松露测试问题,迁移成功,测试耗尽气体,加上测试文件。)

当我添加TestProcessApplicants.sol文件时,汽油用完了。我怀疑这也是正确的,因为在实体测试中实例化了本地实例来测试一些修饰符。

模块TransactionCost CredentialOrgFactory 2209646 CredentialFactory 1934056 SafeMath32 74748 ApplicantFactory 2432336 ProcessApplicants 1937776总计8588562

我怀疑需要一个3_deploy_contracts.js文件。我需要能够在下面的部署中设置引用地址,但我需要能够看到以前的(2_deploy_contracts.js)实例。我该怎么做?还是有更好的方法?或者我只是“做错了”。LOL。

这是2_deploy_contracts.js

代码语言:javascript
复制
var SafeMath32 = artifacts.require("./SafeMath32.sol");
var CredentialOrgFactory = artifacts.require("CredentialOrgFactory");  
var CredentialFactory = artifacts.require("CredentialFactory");        
var ApplicantFactory = artifacts.require("ApplicantFactory");          
var ProcessApplicants = artifacts.require("ProcessApplicants");

module.exports = async function(deployer, accounts) {
    let safeMathInst, aInst, bInst, cInst, dInst;

    await Promise.all([
    deployer.deploy(SafeMath32),
    deployer.deploy(CredentialOrgFactory),
    deployer.deploy(CredentialFactory),
    deployer.deploy(ApplicantFactory),
    deployer.deploy(ProcessApplicants),
    deployer.link(SafeMath32, [CredentialOrgFactory,CredentialFactory,ApplicantFactory])
]);  

instances = await Promise.all([
    SafeMath32.deployed(),
    CredentialOrgFactory.deployed(),
    CredentialFactory.deployed(),
    ApplicantFactory.deployed(),
    ProcessApplicants.deployed(),
])

aInst = instances[1];
bInst = instances[2];
cInst = instances[3];
dInst = instances[4];

results = await Promise.all([  
    // Set Address of bInst so it can point at aInst
    console.log("setAddress CredentialFactory: for CredentialOrgFactory"),
    bInst.setAddress(aInst.address),
    // Set Address of cInst so it can point at aInst
    cInst.setAddress(aInst.address),
    // Set Address of dInst so it can point at aInst, bInst, and cInst
    dInst.setAddress(aInst.address, bInst.address, cInst.address)
    ]);

};
EN

回答 1

Ethereum用户

发布于 2018-08-20 07:49:35

另一种解决特弗斯移民问题的办法:

Add web3 v1到您的 package.json文件:

代码语言:javascript
复制
  "devDependencies": {
    "web3": "1.0.0-beta.34",
    ...
  }

Create帮助文件 util.js**:**

代码语言:javascript
复制
let fs = require("fs");
let Web3 = require("web3");

let web3 = new Web3(NODE_ADDRESS);

async function send(transaction, gasMul = 1, gasAdd = 0) {
    let gas = await transaction.estimateGas({from: PUBLIC_KEY});
    let options = {
        to  : transaction._parent._address,
        data: transaction.encodeABI(),
        gas : gas * gasMul + gasAdd
    };
    let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
    return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
}

async function deploy(contractName, contractArgs) {
    let abi = fs.readFileSync(contractName + ".abi").toString();
    let bin = fs.readFileSync(contractName + ".bin").toString();
    let contract = new web3.eth.Contract(JSON.parse(abi));
    let handle = await send(contract.deploy({data: "0x" + bin, arguments: contractArgs}));
    console.log(`${contractName} contract deployed at address ${handle.contractAddress}`);
    return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
}

function deployed(contractName, contractAddr) {
    let abi = fs.readFileSync(contractName + ".abi").toString();
    return new web3.eth.Contract(JSON.parse(abi), contractAddr);
}

使用In您的部署脚本,如下所示:

文件2_deploy_contracts.js:

代码语言:javascript
复制
let util = require("./util.js");
...
async function run() {
    let myContract = await util.deploy("MyContract", [arg1, arg2, arg3]);
    // Do asynchronous stuff with myContract...
}
...
run();

文件3_deploy_contracts.js:

代码语言:javascript
复制
let util = require("./util.js");
...
async function run() {
    let myContract = util.deployed("MyContract");
    // Do asynchronous stuff with myContract...
}
...
run();

使用NodeJS: Execute这些部署脚本

代码语言:javascript
复制
node 2_deploy_contracts.js
node 3_deploy_contracts.js

<#>I建议从命令行传递系统配置,即:

在每个部署脚本中,添加以下内容:

代码语言:javascript
复制
let NODE_ADDRESS = process.argv[2];
let PUBLIC_KEY   = process.argv[3];
let PRIVATE_KEY  = process.argv[4];

然后将这些值传递给util模块。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/56910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档