When deploying a smart contract, I get this message: "Error: invalid sender undefined." See details below. Why is this happening? What do I need to do differently?
I wrote the smart contract below and compiled it on Remix online IDE(this).
pragma solidity ^0.4.0;
////////////////////////////////////////////////////////////
// This is an password contract which included new,verify,delete,change password
// it also includes the user here.
////////////////////////////////////////////////////////////
contract userPasswd
{
mapping(bytes32 => bytes32) private userPasswds ;
event RecordReturnResult(bool res);
/// @dev new the pair of user and password to the array here
function newPair(string user, string password) returns (bool) {
bytes32 sha3_user = sha3(user);
bytes32 sha3_password = sha3(password);
bool res = true;
if (userPasswds[sha3_user] > 0) {
res = false;
RecordReturnResult(res);
return res;
}
else{
userPasswds[sha3_user] = sha3_password;
res = true;
RecordReturnResult(res);
return res;
}
}
/// @dev verify the pair of user and password stored in the blockchain
function verify(string user, string password) returns (bool) {
bytes32 sha3_user = sha3(user);
bytes32 sha3_password = sha3(password);
//userPasswd[sha3_user] = sha3_password;
//check it
if (userPasswds[sha3_user] == sha3_password){
RecordReturnResult(true);
return true;
}
else{
RecordReturnResult(false);
return false;
}
}
/// @dev delete the pair of user and password stored in the blockchain
function del(string user) returns (bool) {
bytes32 sha3_user = sha3(user);
if (userPasswds[sha3_user] > 0){
delete userPasswds[sha3_user];
RecordReturnResult(true);
return true;
}
else {
RecordReturnResult(false);
return false;
}
}
/// @dev change the pair of user and password stored in the blockchain
function change(string user, string password) returns (bool) {
bytes32 sha3_user = sha3(user);
bytes32 sha3_password = sha3(password);
if (userPasswds[sha3_user] > 0){
userPasswds[sha3_user] = sha3_password;
RecordReturnResult(true);
return true;
}
else {
RecordReturnResult(false);
return false;
}
}
}
After compiling in Remix, I copy the content of (the “Web3 deploy” text box) and paste it into the geth console. The content of the “Web3 deploy” text box is :
var browser_queue_sol_queueContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"d","type":"uint256"}],"name":"addRequest","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"queueLength","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"popRequest","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_element","type":"uint256"}],"name":"ElementPopped","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_element","type":"uint256"},{"indexed":false,"name":"_index","type":"uint256"}],"name":"ElementPushed","type":"event"}]);
var browser_queue_sol_queue = browser_queue_sol_queueContract.new(
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000c57fe5b5b60c860006000018161001f9190610026565b505b610077565b81548183558181151161004d5781836000526020600020918201910161004c9190610052565b5b505050565b61007491905b80821115610070576000816000905550600101610058565b5090565b90565b6102b0806100866000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634ca1fad814610051578063ab91c7b014610071578063e4690a0b14610097575bfe5b341561005957fe5b61006f60048080359060200190919050506100a9565b005b341561007957fe5b6100816100b8565b6040518082815260200191505060405180910390f35b341561009f57fe5b6100a76100ca565b005b6100b460008261010d565b5b50565b60006100c460006101b4565b90505b90565b7fe32433683389a476fe90f93c07386d118310387cc5442554f0f6c2cc839c59426100f560006101c9565b6040518082815260200191505060405180910390a15b565b6101168261025a565b156101215760006000fd5b8082600001836002015481548110151561013757fe5b906000526020600020900160005b50819055507fef848106789acd461bcac88ec81e355ecd41e4be7d7491a567cca53a6cbcec96818360020154604051808381526020018281526020019250505060405180910390a1816000018054905060018360020154018115156101a657fe5b0682600201819055505b5050565b6000816001015482600201540390505b919050565b60008160010154826002015414156101e057610255565b8160000182600101548154811015156101f557fe5b906000526020600020900160005b5054905081600001826001015481548110151561021c57fe5b906000526020600020900160005b50600090558160000180549050600183600101540181151561024857fe5b0682600101819055508090505b919050565b600081600101548260000180549050600184600201540181151561027a57fe5b061490505b9190505600a165627a7a723058202bf2e05f5b798836d525200eda8f26ec77b1773fb691c8877b80de58e03867910029',
gas: '470000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
and the console shows:
Error: invalid sender undefined
undefined
the geth version is: Version: 1.6.6-unstable. go version is : go1.9beta2 windows/amd64
eth.accounts? Does it show a non-empty array? If it's empty you need to create (and fund) an account first:geth account newin your terminal. – Joël Jul 10 '17 at 07:27eth.getBalance('0x72b1897d547548148dae04813cb4920d3c66810f')and see what it says? Also, logweb3.eth.accounts[0]in the code to make sure web3 finds it. – Joël Jul 10 '17 at 07:56web3.eth.accounts[0]
"0x72b1897d547548148dae04813cb4920d3c66810f"
– jiebang Jul 10 '17 at 08:18eth.getBalance('0x72b1897d547548148dae04813cb4920d3c66810f')
2.575e+21
– jiebang Jul 10 '17 at 08:26