carlos
August 2, 2023, 11:17am
1
I initially copied this code from the sway examples github:
fn initialize(exchange_bytecode_root: ContractId) {
require(storage.exchange_bytecode_root.read().is_none(), InitError::BytecodeRootAlreadySet);
storage.exchange_bytecode_root.write(Option::Some(exchange_bytecode_root.into()));
}
However i get the error:
“” ^^^^ No method named “read” found for type “Option”.“”"
Could someone explain me this error and maybe even more important. Explain the need to initialise the contract here? I dont see it in other examples?
david
August 2, 2023, 2:00pm
2
What version of forc are you using? The error you mentioned seems to be the result of using an older version of Fuel & Sway.
As for why there’s an initializer: Sway doesn’t have constructors like Solidity. If you need to initialize storage slots, there must be an initialize function.
carlos
August 2, 2023, 3:43pm
3
I am using forc 0.37.3 and fuel-core 0.17.11
So basically you are trying to run newer code with an older compiler
Please run
fuelup toolchain install latest
and then
fuelup default latest
Let me know if it works
carlos
August 2, 2023, 3:52pm
5
sandusky:
fuelup default latest
Thanks @sandusky and @david That was it.
1 Like
system
Closed
August 23, 2023, 11:53am
6
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.