如何在Node.js上以固体@ 0.5.0部署工厂合同

时间:2019-08-02 10:43:25

标签: blockchain ethereum solidity web3 web3js

回购:https://github.com/aljmiller87/ethereum-dispute-resolution

我有一个固体文件@ 0.5.0,带有工厂合同和子合同。我可以编译(尽管您会在ethereum / compile.js中所有注释掉的行中注意到试验和错误)。

运行... options.CallbackPath = "signin-oidc/b"; ... 会导致错误。

node ethereum/deploy.js

我已经确认此合同代码可以混音使用。 我尝试在Attempting to deploy from account 0xff831110eeA8322639bee543AD1477AD9f472E22 UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit. ... ... ... UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:24059) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. truffle-hdwallet-provider上使用0.0.3(并相应地更新.deploy()和.send()参数。

我在solidity 0.4.17的另一个项目上使用了此精确设置,并且部署工作正常(尽管编译有所不同)。这是上一个项目的仓库:https://github.com/aljmiller87/ethereum-kickstart

回购:https://github.com/aljmiller87/ethereum-dispute-resolution

ethereum / deploy.js

0.0.5

package.json:

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const compiledContract = require('./build/ThreeJudge.json');

const compiledFactory = compiledContract.ContractFactory
const compiledFactoryABI = compiledFactory.abi;
const compiledFactoryBytecode = compiledFactory.evm.bytecode.object;


const provider = new HDWalletProvider(
    `${process.env.SEED_KEY}`,
    'https://rinkeby.infura.io/v3/ad66eb1337e043b2b50abe1323fff5f0'
);

const web3 = new Web3(provider);

const deploy = async () => {
    // Get account to deploy from
    const accounts = await web3.eth.getAccounts();
    console.log('Attempting to deploy from account', accounts[0]);

    // deploy code
    const result = await new web3.eth.Contract(compiledFactoryABI)
    .deploy({ data: '0x' + compiledFactoryBytecode })
    .send({ gas: '1000000', from: accounts[0] });


    console.log('result address', result.options.address)
};

deploy();


运行{ "name": "kickstart", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "mocha test/ThreeJudge.test.js --timeout 10000", "test-local": "mocha test/ThreeJudge-local.test.js --timeout 10000", "dev": "node server.js" }, "author": "", "license": "ISC", "dependencies": { "dotenv": "^8.0.0", "fs-extra": "^8.1.0", "ganache-cli": "^6.5.0", "mocha": "^6.1.4", "next": "^4.1.4", "next-routes": "^1.4.2", "path": "^0.12.7", "react": "^16.8.6", "react-dom": "^16.8.6", "semantic-ui-css": "^2.4.1", "semantic-ui-react": "^0.87.3", "solc": "0.5.2", "truffle-hdwallet-provider": "0.0.5", "web3": "^1.0.0-beta.37" } } 会导致错误。

node ethereum/deploy.js

2 个答案:

答案 0 :(得分:1)

您可以使用克隆工厂合同代替新关键字,因为它在汽油方面非常便宜,这是参考链接:clone-factory以及为什么更好"Attack Of The Clones — How DDA Contracts Are So Cheap To Deploy"

答案 1 :(得分:0)

发现问题出在坚固性代码中。我试图保留合同类型的数组,而不是保留创建的合同的地址。

原文:

contract ContractFactory {
    ThreeJudge[] public deployedContracts;

    function createContract(address payable _buyer, address payable _seller) public {
        ThreeJudge newContract = new ThreeJudge(_buyer, _seller);
        deployedContracts.push(newContract);
    }

    function getDeployedContracts() public view returns (ThreeJudge[] memory) {
        return deployedContracts;
    }
}

contract ThreeJudge {
...

修复:

contract ContractFactory {
    address[] public deployedContracts;

    function createContract(address payable _buyer, address payable _seller) public {
        ThreeJudge newContract = new ThreeJudge(_buyer, _seller);
        deployedContracts.push(address(newContract));
    }

    function getCampaignsByAddress() public view returns (address[] memory) {
        return deployedContracts;
    }
}

contract ThreeJudge {
...