简体   繁体   English

"合约代码无法存储,请检查您的gas限制:以太坊智能合约部署失败:"

[英]The contract code couldn't be stored, please check your gas limit : Ethereum Smart Contract Deployment Failed:

I'm learning how Ethereum Smart Contract<\/strong> are developed and deployed using solidity, web3 and Javascript.我正在学习如何使用solidity、web3 和Javascript 开发和部署以太坊智能合约<\/strong>。

I've successfully deployed a contract on Ganache<\/code><\/strong> .我已经成功地在Ganache<\/code><\/strong>上部署了一个合约。 Now when I'm trying to deployed it on Rinkby Test Net<\/code><\/strong> using truffle-hdwallet-provider<\/code><\/strong> It just fail.现在,当我尝试使用truffle-hdwallet-provider<\/code><\/strong>在Rinkby Test Net<\/code><\/strong>部署它时,它只是失败了。

Ive sucessfully created web3<\/code><\/strong> object using truffle-hdwallet-provider<\/code><\/strong> and I sucessfullly get the account list but the deployment to the testnet always get failed.我使用truffle-hdwallet-provider<\/code><\/strong>成功创建了web3<\/code><\/strong>对象,并且我成功获得了帐户列表,但部署到测试网总是失败。

You can check here that my deployment gets failed.<\/strong>您可以在此处检查我的部署是否失败。<\/strong>

https:\/\/rinkeby.etherscan.io\/address\/0x2f20b8F61813Df4e114D06123Db555325173F178<\/a> https:\/\/rinkeby.etherscan.io\/address\/0x2f20b8F61813Df4e114D06123Db555325173F178<\/a>

<\/blockquote>

Here is my deploy script<\/code>这是我的deploy script<\/code>

 const HDWalletProvider = require('truffle-hdwallet-provider'); const Web3 = require ('web3'); const {interface, bytecode} = require('.\/compile'); const provider = new HDWalletProvider( 'memonics', \/\/ this is correct 'https:\/\/rinkeby.infura.io\/mylink' \/\/ this is correct ); const web3 = new Web3(provider); const deploy = async() =>{ const accounts = await web3.eth.getAccounts(); console.log('Attempting to deploy from account:', accounts[0]); \/\/This excute fine try { const result = await new web3.eth.Contract(JSON.parse(interface)).deploy({ data: bytecode, arguments: ['Hi There!']}).send({ from: accounts[0], gas: '1000000'}); console.log('Contract deployed to ', result.options.address); } catch(err) { console.log('ERROR'); \/\/ Here I get error } }; deploy();<\/code><\/pre>

and here is my Contract这是我的合同

pragma solidity ^0.4.17; contract Inbox{ string public message; constructor (string initialMessage) public { message = initialMessage; } function setMessage(string newMessage) public { message = newMessage; } }<\/code><\/pre>

EDIT: I tried using Remix<\/strong> and it deployed successfully but when trying with truffle-hdwallet-provider<\/strong> it gives error: The contract code couldn't be stored, please check your gas limit.<\/strong>编辑:我尝试使用Remix<\/strong>并成功部署,但尝试使用truffle-hdwallet-provider<\/strong>时出现错误:无法存储合约代码,请检查您的气体限制。<\/strong> I tied with different gas values (up-to max possible) but still no result.我绑定了不同的气体值(可能达到最大值),但仍然没有结果。

"

I figured out the bytecode do not include 0x Causing this problem. 我发现bytecode不包含0x导致此问题。

By Concating 0x with the bytecode solved the problem. 通过将0x与字节码连接可以解决此问题。

I had this problem, and solved it by pasting the flattened code into Remix that then gave a better error description: I had an interface in the contract that I had not implemented correctly (wrong function signature). 我遇到了这个问题,并通过将扁平化的代码粘贴到Remix中来解决了该问题,然后给出了更好的错误描述:合同中有一个我未正确实现的接口(错误的函数签名)。 Check your interface implementations. 检查您的界面实现。 Trying to deploy an "abstract contract" gives this error. 尝试部署“抽象合同”会出现此错误。

use this '0x0' + just before bytecode.在字节码之前使用这个 '0x0' +。

.deploy({ data:'0x0' + bytecode }) .send({ gas: "1000000", gasPrice: "5000000000", from: accounts[0] }); .deploy({ data:'0x0' + bytecode }) .send({ gas: "1000000", gasPrice: "5000000000", from: accounts[0] });

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM