The Solidity Contract-Oriented Programming Language - By chatting here you agree to the https://github.com/ethereum/solidity/blob/develop/CODE_OF_CONDUCT.md
function registerCar(string memory _liscence, string memory _color, string memory _brand, string memory _model) public{
totalCars++;
car memory newCar = car({
liscence: _liscence,
serialNumber: totalCars,
color: _color,
brand: _brand,
model: _model
});
carSerialNumber[totalCars] = newCar;
}
pragma solidity ^0.5.0;
contract carRegister{
struct car{
string liscence;
string color;
string brand;
string model;
uint256 serialNumber;
}
uint256 public totalCars = 0;
mapping(uint256 => car) public carSerialNumber;
function registerCar(string memory _liscence, string memory _color, string memory _brand, string memory _model) public{
totalCars++;
car memory newCar = car({
liscence: _liscence,
serialNumber: totalCars,
color: _color,
brand: _brand,
model: _model
});
carSerialNumber[totalCars] = newCar;
}
}
web3.eth.getTransactionCount(config.contract.accountAddress).then(function(nonceVal){
let transactionObject = {
from: config.contract.accountAddress,
nonce: web3.utils.toHex(nonceVal),
gas: gasLimit,
gasPrice: gasPrice
}
return carRegister.methods.registerCar(carDetails.liscence, carDetails.color, carDetails.brand, carDetails.model )
.send(transactionObject)
.on('transactionHash', function(hash){
console.log( "Hash", hash );
})
.on('confirmation', function(confirmationNumber, receipt){
console.log( "confirmationNumber:", confirmationNumber );
})
.on('receipt', function(receipt){
console.log("receipt:", receipt);
})
.on('error', console.error)
.catch(function(error){
console.log( "failed somewhere", error);
return {"registered": "false"};
})