-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Hi. I am enjoying your tutorial, but I am stuck with deploy.js
The default deploy.js does not work. Can you help me, please?
When I run node, I get:
$ node deploy.js
/Users/mig/etheretc/webthereum/node/node_modules/solc/soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath"normalize";var ret=n
TypeError: web3.eth.getTransactionCount(...).then is not a function
at deployContract (/Users/mig/etheretc/webthereum/node/deployDef.js:12:61)
at Object. (/Users/mig/etheretc/webthereum/node/deployDef.js:8:1)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:617:3
So I tried to workaround the ".then" statement and then I had many more exceptions and errors.
This is the final version with such error:
"txn err Error: exceeds block gas limit"
deploy.js:
function deployContract() {
// txnCount = console.log(web3.eth.getTransactionCount(process.env.RINKEBY_ADDRESS));
txnCount = web3.eth.getTransactionCount(process.env.RINKEBY_ADDRESS);
console.log(txnCount);
// web3.eth.getTransactionCount(process.env.RINKEBY_ADDRESS).then((txnCount) => {
// // txnCount => {
console.log("txn count", txnCount);
const source = fs.readFileSync(__dirname+'/../truffle/contracts/MyPrize.sol');
const compiled = solc.compile(source.toString(), 1);
const bytecode = compiled.contracts[':MyPrize'].bytecode;
const rawContractTx = {
// from: process.env.RINKEBY_ADDRESS, nonce: web3.utils.toHex(txnCount), gasLimit: web3.utils.toHex(4000000), gasPrice: web3.utils.toHex(20000000000), data: '0x' + bytecode,
from: process.env.RINKEBY_ADDRESS,
// nonce: web3.utils.toHex(txnCount),
// gasLimit: web3.utils.toHex(4000000),
// gasPrice: web3.utils.toHex(20000000000),
nonce: web3.toWei(txnCount, "ether"),
gasLimit: web3.toWei("4000", "ether"),
gasPrice: web3.toWei("20000000", "ether"),
data: '0x' + bytecode,
// web3.utils.toWei("0.001", "ether"),
};
console.log("contract deploying...");
// console.log(rawContractTx);
sendRaw(rawContractTx);
// });
// };
}
function showABI() {
const source = fs.readFileSync(__dirname+'/../truffle/contracts/MyPrize.sol');
const compiled = solc.compile(source.toString(), 1);
const abi = compiled.contracts[':MyPrize'].interface;
console.log("abi", abi);
}
function sendRaw(rawTx) {
var privateKey = new Buffer(process.env.RINKEBY_KEY, 'hex');
var transaction = new tx(rawTx);
transaction.sign(privateKey);
var serializedTx = transaction.serialize().toString('hex');
// web3.eth.sendSignedTransaction(
web3.eth.sendRawTransaction(
'0x' + serializedTx, function(err, result) {
if(err) {
console.log("txn err", err);
} else {
console.log("txn result", result);
} });
}