我正在浏览以太坊网站上的第一个教程。
我已经使用 Remix 编译了合约代码并创建了以下脚本。为简洁起见,我删除了二进制字符串:
var _greeting = 'Hello World!';
var browser_untitled_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var browser_untitled_sol_greeter = browser_untitled_sol_greeterContract.new(
_greeting,
{
from: web3.eth.accounts[0],
data: 'BINARY_STRING',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
var browser_untitled_sol_mortalContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var browser_untitled_sol_mortal = browser_untitled_sol_mortalContract.new(
{
from: web3.eth.accounts[0],
data: 'BINARY_STRING',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
加载此脚本时,我得到:
Error: insufficient funds for gas * price + value
.
打电话时eth.getBalance(eth.accounts[0])
我得到:399577000000000
我不知道我的余额中应该有多少 eth 才能运行这个脚本,或者我是否需要将 eth 转换为 gas。