You can get dynamic array like this : uint256[] public machineList by creating a contract getter function.
function getMachineList () external returns (uint256[]){
return machineList
}
note the external modifier i added, in this kind of functions where you are returning a dynamically sized array the external modifier is mandatory. it also makes the function only callable from the exterior of the contract which is exactly what we want here.
An other thing is that you are using truffle to call contract functions. When using truffle you need to call a promise (or a callback) after the name of the function :
AssetContract.deployed().then(function (contractInstance) {
contractInstance.getMachineList.
call(**arguments if any**,{ from:**address**, gas: 300000 }).then(
data => {
var MachineList = data;
alert(MachineList);
}
)
})
Note: whenu sing truffle you add the .call()
if you are just calling functions that read and return variables as if it will not alter state variables (change/add existing/new value).
Since you mentioned in comments that you're open to using web3.py v5, here is the v5 approach to sign a message:
from eth_account import Account, messages
msg_hash_hex = "058c3b4c8e5dc4632b5c6b861b2c1861d53e426dc673c907ddf2651942b0f230"
private_key_hex = "b25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364"
#// This part prepares "version E" messages, using the EIP-191 standard
message = messages.encode_defunct(hexstr=msg_hash_hex)
#// This part signs any EIP-191-valid message
signed_message = Account.sign_message(message, private_key=private_key_hex)
print("signature =", signed_message.signature.hex())
If you'd like to know more about EIP-191, check out the original EIP-191 writeup. It's short and readable.
That snippet is equivalent to the javascript:
msgHash = "0x058c3b4c8e5dc4632b5c6b861b2c1861d53e426dc673c907ddf2651942b0f230"
privateKeyUser = "b25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364"
// web3.js sign() *only* supports "version E" EIP-191 signing
// so it adds the preamble for you.
let signature = await web3.eth.accounts.sign(msgHash, '0x' + privateKeyUser);
console.log('signature ='+signature.signature);
Note that the javascript sign()
method "signs arbitrary data" rather than a message hash. So although you appear to be hashing it first, you could sign the original message instead.
In the python version, prepare the original message for signing with: encode_defunct(text=original_message)
.
Best Answer
Yes:
Contract is an object that was created from w3.eth.contract