When i use some web3 options as follows, I receive a common error i.e.
TypeError: web3.[option] is not a function
For example :
TypeError: web3.toAscii is not a function
web3.toAscii(0x37361fd8eb5f78c7558ccfaa338c1935ecbc3d486f7a63c5b3e1b245779bc90e.input)
TypeError: web3.toAscii is not a function
And I receive same error using another format of this command as follows :
var str = web3.toAscii("0x37361fd8eb5f78c7558ccfaa338c1935ecbc3d486f7a63c5b3e1b245779bc90e");
console.log(str);
Or
TypeError: MyContract.MyEvent is not a function
var Ev = contractInstance.LogNewObject({}, {fromBlock: 0, toBlock: 'latest'});
Ev.get((error, events) => {
if (!error) {
function ShowResults(event) {
console.log('sub_states_types: ' + event.args.sub_states_types);
console.log('sub_states_values: ' + event.args.sub_states_values);
}
events.forEach(ShowResults);
} else {
console.log('Error');
}
});
And my smart contract is as follows :
pragma solidity 0.4.23;
contract RFID {
struct StateStruct {
bytes32 description;
mapping(bytes32 => bytes32) sub_state;
}
struct ObjectStruct {
StateStruct state;
address owner;
bool isObject;
}
mapping(bytes32 => ObjectStruct) objectStructs;
bytes32[] public objectList;
event LogNewObject(address sender, bytes32 indexed id, bytes32 sub_states_types, bytes32 sub_states_values, address owner);
event LogChangeObjectState(address sender, bytes32 indexed id, bytes32 sub_states_types, bytes32 sub_states_values);
event LogChangeObjectOwner(address sender, bytes32 indexed id, address newOwner);
function isObject(bytes32 _id) public view returns(bool isIndeed) {
return objectStructs[_id].isObject;
}
function getObjectCount() public view returns(uint count) {
return objectList.length;
}
/*function setArraySize(uint256 _number_of_sub_states) public {
number_of_sub_states = _number_of_sub_states;
}
function getArraySize() view public returns (uint256) {
return number_of_sub_states;
}*/
function newObject(bytes32 _id, uint256 number_of_sub_states, bytes32[10] sub_states_types, bytes32[10] sub_states_values, address _owner) public returns(bool success) {
require(!isObject(_id));
uint256 counter=0;
for(counter; counter < number_of_sub_states; counter++) {
objectStructs[_id].state.sub_state[sub_states_types[counter]] = sub_states_values[counter];
emit LogNewObject(msg.sender, _id, bytes32(sub_states_types[counter]), bytes32(sub_states_values[counter]), _owner);
}
objectStructs[_id].owner = _owner;
objectStructs[_id].isObject = true;
objectList.push(_id);
return true;
}
function changeObjectState(bytes32 _id, uint256 number_of_sub_states, bytes32[10] sub_states_types, bytes32[10] sub_states_values) public returns(bool success) {
require(isObject(_id));
uint256 counter=0;
for(counter; counter < number_of_sub_states; counter++) {
objectStructs[_id].state.sub_state[sub_states_types[counter]] = sub_states_values[counter];
emit LogChangeObjectState(msg.sender, _id, bytes32(sub_states_types[counter]), bytes32(sub_states_values[counter]));
}
//objectStructs[_id].state = StateStruct(_newState);
//emit LogChangeObjectState(msg.sender, _id, _newState);
return true;
}
function changeObjectOwner(bytes32 _id, address _newOwner) public returns(bool success) {
require(isObject(_id));
objectStructs[_id].owner = _newOwner;
emit LogChangeObjectOwner(msg.sender, _id, _newOwner);
return true;
}
}
Whate is the reason ?