标签: ethereum

部署智能合约时“未定义”的参数数量无效

我正在尝试在 testRPC 上部署我的第一个投票合约,下面是我的代码..出于某种原因,当我开始部署时它会抱怨。

错误似乎来自 arguments 参数。我尝试传递一个空数组,它说“得到 0 预期 1!”。我试着只传递一个名字,它说“value.forEach”不是一个函数。

Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
sourceCode = fs.readFileSync('Voting.sol').toString()
solc = require('solc')
compiledCode = solc.compile(sourceCode)
abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface)
VotingContract = new web3.eth.Contract(abiDefinition)
byteCode = compiledCode.contracts[':Voting'].bytecode

VotingContract.deploy({
    data: byteCode, 
    arguments:['Joseph','Sean','Matthew']
}).send({
    from: '0x00D1AE0A6fC13B9ecdefA118B94cF95ac16D4ab0', 
    gas: 4700000
})
.on('error', function(error) {
    console.log(error);
}
.then(function(newContractInstance) {
    console.log(newContractInstance.options.address)
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激。谢谢你。

node.js ethereum solidity web3js web3-donotuse

1
推荐指数
1
解决办法
5274
查看次数

Solidity 中的断言与要求?

我的理解是,如果失败,“require”会退还剩余的gas,而“assert”则不会。

我有点困惑,尽管 b/c 剩余气体是什么意思?我经常指定一个非常大的 gas 限制,即使我调用的合同需要很少。

如果我指定 4,700,000 gas 限制,并且只需要 50,000 gas,但是在被调用的合约中“assert”失败,我会失去所有 4,700,000 gas 吗?

ethereum

1
推荐指数
1
解决办法
1389
查看次数

在云功能模块中集成web3

我正在尝试将 web3(使用 truffle)集成到云功能模块中,但我不断收到此错误:

Error: Invalid JSON RPC response: ""
Run Code Online (Sandbox Code Playgroud)

这是实现的一部分:

admin.initializeApp(functions.config().firebase);

const db = admin.database();

const provider = new HDWalletProvider(mnemonic, infura link);

const web3 = new Web3(provider);
Run Code Online (Sandbox Code Playgroud)

据我了解,该错误表明松露库无法建立与复仇网络的连接。我想知道这是否与将此代码部署到 firebase 有关。

提前致谢。

firebase ethereum google-cloud-functions truffle web3js

1
推荐指数
1
解决办法
875
查看次数

合同中应支付的坚固性建设者

我有以下代码出现故障,无法从另一个合同创建应付合同。

pragma solidity ^0.4.16;

Contract Factory {
    uint contractCount = 0;
    mapping(uint => MyContract) public myContracts;

    function createContract(uint money) external payable {
        require(msg.value >= money);
        contractCount++;
        // the following line fails
        myContracts[contractCount] = new MyContract(money);
    }
}

Contract MyContract {
    uint money;

    function MyContract(uint _money) {
        require(msg.value >= _money);
        money = _money;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 Remix IDE。我可以毫无问题地创建 Factory 实例,但是,当我尝试 createContract(money) 时,它无法创建新的 MyContract 实例。我怀疑这是因为调用的方式new MyContract()没有传输任何值,因此MyContract构造函数中的 require(msg.value >= _money) 失败。

那么如何从合约创建一个可支付构造函数的实例呢?

ethereum solidity smartcontracts

1
推荐指数
2
解决办法
2528
查看次数

如何`geth init`并使用Docker-compose开始geth挖掘?

我想用 Docker 创建私有以太坊网络。我已经准备好了创世文件,所以我需要geth init genesis.json然后开始像geth --mine .... 我可以用脚本来做(比如这里:https : //github.com/vertigobr/ethereum/blob/master/runminer.sh#L5https://github.com/vertigobr/ethereum/blob/master/runnode。 sh#L23):

if [ ! -d $DATA_ROOT/keystore ]; then
    echo "$DATA_ROOT/keystore not found, running 'geth init'..."
    docker run --rm \
        -v $DATA_ROOT:/root/.ethereum \
        -v $(pwd)/genesis.json:/opt/genesis.json \
        $IMGNAME init /opt/genesis.json
    echo "...done!"
fi
echo "Running new container $CONTAINER_NAME..."
docker run $DETACH_FLAG --name $CONTAINER_NAME \
    --network ethereum \
    -v $DATA_ROOT:/root/.ethereum \
    -v $DATA_HASH:/root/.ethash \
    -v $(pwd)/genesis.json:/opt/genesis.json \
    $RPC_PORTMAP \
    $IMGNAME --bootnodes=$BOOTNODE_URL $RPC_ARG --cache=512 --verbosity=4 --maxpeers=3 …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose ethereum geth

1
推荐指数
1
解决办法
1161
查看次数

在发送到以太坊网络之前,智能合约函数的输入数据如何打包成十六进制字符串

我想了解这一点以解析来自私有链交易的数据并获取为特定交易发送的输入数据,我尝试了许多解码器,但在某些时候,它们失败了。这是我尝试使用 remix 的简单智能合约

   contract simple{

     uint256 deliveryID;
     string status;
     function stringAndUint(string _status,uint256 _deliveryID){
               status=_status;
               deliveryID=_deliveryID;
     }

    } 
Run Code Online (Sandbox Code Playgroud)

产生的输入数据: - 0x3c38b7fd0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000067374617475730000000000000000000000000000000000000000000000000000

我可以从上面解释以下内容。

  • 函数签名:0x3c38b7fd
  • _状态值:737461747573,
  • _deliveryID:0c 但我不知道为什么 737461747573 之前有 4 个和额外的 6 个。
  • 函数“stringAndUint”的输入是:“status”,12有人能帮我理解输入数据是如何生成的,并以一个长的十六进制字符串分组

ethereum

1
推荐指数
1
解决办法
1455
查看次数

以太坊坚固性计算的奇怪行为

我在简单的solidity代码下面写了这个来计算一些数字。但是,以太坊区块链在每个函数上给出不同的输出。我的代码有什么问题还是以太坊区块链问题?

我的可靠性代码:

pragma solidity ^0.4.24;

contract Calculate {

    uint balance = 50000000000000000000;

    function done() public pure returns (uint) {
        return (50000000000000000000 / 3000) * 3000;
    }

    function fail() public view returns (uint) {
        return (balance / 3000) * 3000;
    }

}
Run Code Online (Sandbox Code Playgroud)

输出:

done() function returns 50000000000000000000

fail() function returns 49999999999999998000
Run Code Online (Sandbox Code Playgroud)

请在此处查看现场示例: https : //ropsten.etherscan.io/address/0xf45a2a66be9835fdc9e1065875808616cb8e752e#readContract

blockchain ethereum solidity calculation

1
推荐指数
1
解决办法
113
查看次数

未定义的 window.web3

当我尝试通过 web3js 和 MetaMask 调用以太坊智能合约时,我遇到了获取 window.web3 的问题。该消息表示该值未定义。

<script src="jquery.min.js"></script>
<script src="web3.min.js"></script>

<script type="text/javascript">

window.addEventListener('load',
function() {
    $("#loader").hide();

 	console.log('!');
	web3 = window.web3;
	console.log(web3);

    // Checking if Web3 has been injected by the browser (Mist/MetaMask)
    if (typeof web3 !== 'undefined') {
        // Use Mist/MetaMask's provider
        web3 = new Web3(web3.currentProvider);
        window.web3 = new Web3(web3.currentProvider);

    	console.log(web3.currentProvider);

        if (web3.currentProvider.isMetaMask === true) {

            startApp();
        } else {

            $('#results').html('No web3? Please use google chrome and metamask plugin to enter this Dapp!');

        }
    }
});
...
Run Code Online (Sandbox Code Playgroud)

安慰:

! …

javascript ethereum web3js web3-donotuse metamask

1
推荐指数
1
解决办法
2190
查看次数

返回坚固度为 0.5.0 的字符串。数据位置必须是函数中返回参数的“内存”

如何在 0.5.0 solidity 编译器版本中返回字符串?

contract Test {
    string public text = 'show me';
    function  test() public view returns (string) {
        return text;
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

TypeError: Data location must be "memory" for return parameter in function, but none was given.
Run Code Online (Sandbox Code Playgroud)

ethereum solidity smartcontracts

1
推荐指数
1
解决办法
4981
查看次数

如何通过web3将地址类型转换为bytes32?

我有需要以bytes32输入的合同,所以我需要将地址转换为bytes32,但在web3中看不到这个方法。

ethereum solidity web3-donotuse

1
推荐指数
1
解决办法
1712
查看次数