Ich habe einen Vertrag, bei dem ich gerne Zahlen summieren möchte, die von einer anderen Adresse übermittelt werden:
contract UnitCounter {
mapping (address => uint256) public UnitsFrom;
uint256 public TotalUnits;
function submitUnits(uint256 Units) {
UnitsFrom[msg.sender] = Units;
TotalUnits += Units;
}
}
Mit dieser groben Anleitung habe ich die folgenden Schritte in einem privaten Netz befolgt:
0x17d541b8aACFFe473e3dD32eBA83C82B51DB8EF9
in meine private Blockchain.Auf einer Geth-Konsole:
var abi=[ { "constant": false, "inputs": [ { "name": "Units", "type": "uint256" } ], "name": "submitUnits", "outputs": [], "type": "function" }, { "constant": true, "inputs": [], "name": "TotalUnits", "outputs": [ { "name": "", "type": "uint256" } ], "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "address" } ], "name": "UnitsFrom", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "type": "function" } ]
var MyContract = web3.eth.contract(abi);
var MyContractInstance = MyContract.at('0x17d541b8aACFFe473e3dD32eBA83C82B51DB8EF9');
MyContractInstance.submitUnits('10');
Ich bekomme dann folgende Fehler:
Fehler: ungültige Adresse
bei web3.js:3887:15
bei web3.js:3713:20
bei web3.js:4939:28
bei map ()
bei web3.js:4938:12
bei web3.js:4964:18
bei web3 .js:4989:23
bei web3.js:4055:16
bei apply ()
bei web3.js:4141:16
Was bedeuten diese Fehler?
Wie soll ich von diesem Punkt aus debuggen?
Sie müssen ein Transaktionsobjekt hinzufügen, um Geth mitzuteilen, welches Konto für die Transaktion verwendet werden soll:
MyContractInstance.submitUnits('10', {from: eth.accounts[0], gas:3000000});
Sie können diesen Fehler auch auf diese Weise beheben, indem Sie Ihr Standardkonto festlegen, sodass Sie bei der Interaktion mit Ihrem Vertrag keine Optionen {von:...} hinzufügen müssen.
In Ihrer Geth-Konsole :-
// default account set to first account in your geth accounts
eth.defaultAccount = eth.accounts[0]
// Note: If eth.accounts is empty, you can create a new account with personal.newAccount()
// default account set to coinbase(Etherbase), the default primary local account in geth
eth.defaultAccount = eth.coinbase
Wenn Sie diesen Fehler als nächstes erhalten - Fehler: Authentifizierung erforderlich: Passwort oder Entsperren , entsperren Sie Ihr Konto.
In Ihrer Geth-Konsole :-
// unlocks your account for calls/transactions after you give password
personal.unlockAccount(eth.defaultAccount)