【问题标题】:how to call constructor with arguments in REMIX (Solidity IDE ) from web3如何在 REMIX(Solidity IDE)中从 web3 调用带有参数的构造函数
【发布时间】:2018-10-16 11:43:47
【问题描述】:

所以我使用 Remix IDE 和一个带有该合约参数的构造函数创建了一个名为“Voting”的合约

我通过这样做调用了合同:

var Contractabi = web3.eth.contract(contract Abi from Remix)
 var vote = Contractabi.at(Smart contract @ in REMIX );

所以直到现在一切正常!但现在我需要使用带有参数的构造函数部署智能

我发现很少有这样的方法:

var MyContract = web3.eth.contract(abiArray);

// deploy new contract
var contractInstance = MyContract.new([constructorParam1] [, constructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});

但这对我不起作用! 我怎么能用来自 web3.eth.contract 的 REMIX 中的参数调用我的智能合约构造函数! 谢谢:D

【问题讨论】:

    标签: solidity web3js remix


    【解决方案1】:

    我相信您使用的是较新版本的 web3。您可以恢复到以前的版本 0.20.0 或使用下面的新语法。

    使用 web3 1.0.x 版本时需要传入 Application 二进制接口,即 abi。并使用new 关键字

    文档https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract

        Here is an example
    
        var contractABI = [{your contract abi}] 
        var subtestContract = new web3.eth.Contract(contractABI,{
             from: account1, 
             data: "your contract data", 
             gas: '4700000'
         })
    
        //arguments go inside deploy() using an array as follows
        subtestContract.deploy({arguments: ["hello"]})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-25
      • 2018-09-16
      • 2019-03-28
      • 2015-02-03
      • 2022-01-26
      • 2012-02-26
      • 2020-03-23
      • 2011-10-08
      相关资源
      最近更新 更多