我正在尝试将智能合约部署到使用 oraclizeAPI.sol 库代码的私有区块链。基本上,智能合约是 oraclize 的一个小实现。
导入不起作用,无论是使用 github 链接还是使用本地导入,solc 编译都因导入而失败。
以下两个都不起作用,合同没有被 solc 正确编译
1.import "oraclizeAPI.sol";
2.import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
因此,我采取的下一个方法是将 oraclizeAPI.sol 的代码直接复制到合约代码文件中。现在合同已正确编译,但我每次在部署时都会陷入困境。
错误:
The contract couldn't be stored, please check your gas amount.
现在这里是区块链的详细信息。
创世纪.json
{
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x4000",
"alloc": {
"84840c340067c75806273d2524dfbae646a7c68f":
{ "balance": "1606938044258990275541962092341162602522202993782792835301376" }
},
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase": "0x84840c340067c75806273d2524dfbae646a7c68f",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000000000000"
}
我目前正在尝试使用 coinbase id 来部署合同。
web3.eth.getBlock("latest").gasLimit
132661998547049420
web3.eth.getBalance('0x84840c340067c75806273d2524dfbae646a7c68f').e
60
合约代码:
contract oraclizeExample is usingOraclize {
string public data;
event newOraclizeQuery(string description);
event newData(string data);
event eventC(string data);
function oraclizeExample() payable {
update();
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
data = result;
newData(result);
//return result;
}
function eventCheck(string dataFClient) returns (string) {
eventC(dataFClient);
return dataFClient;
}
function update() payable returns (string) {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "json(https://jewel-api.herokuapp.com/jewel/58d89d264d59a000110829bb).invoice_num");
return "update function was called!";
}
}
合约创建代码。
var ContractABI = web3.eth.contract(JSON.parse(interface));
var SaveContract = ContractABI.new(
{
from: account,
data: bytecode,
gas: '93048696279858031'
}, function (e, contract) {
if(e){
console.log(e, contract);
return;
}
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
fs.writeFileSync('./contracts_data/'+ contract_name + '_final', 'Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash)
return;
}
});
如果您想检查完整的合同代码以及我这样做的方式,请访问此链接。
https://github.com/utkarsh17ife/oraclizeExample/tree/master/contracts_data
或者使用节点的完整实现:
https://github.com/utkarsh17ife/oraclizeExample
是的,我可以使用此设置挖掘其他合约。
如果您需要有关此的更多信息,请发表评论。