Expected behavior: Contract deployed successfully without error
Actual behavior:
const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
^
TypeError: response.body.pipeThrough is not a function
at fuelGraphQLSubscriber (/Users/yuduan/Projects/fuel/node_modules/@fuel-ts/account/dist/index.js:1087:50)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async _Provider.sendTransaction (/Users/yuduan/Projects/fuel/node_modules/@fuel-ts/account/dist/index.js:3898:41)
at async ContractFactory.deployContract (/Users/yuduan/Projects/fuel/node_modules/@fuel-ts/contract/dist/index.js:166:5)
@yuduan0220 Where are you running your code, in nodejs (a server) or in Safari (a web app)? Also, could you please give us a repo with the problematic code?
Hey, I’m running it through cmd line with node version 16.
Another thing I found is that even exception was thrown, the contract was deployed and I could find it on the explorer.
Could you please run it with node v18 or above? We officially support only v18 and v20.
On the note of successful deployment, it shouldn’t be possible for you to even deploy the app with node v16 because we’re using native fetch for all calls, which was only introduced in v17 under an experimental flag and stabilized in v18. I suspect you’ve got something going on with node-fetch being put in place of fetch, which allows you to send the contract deployment request but fails on response.body.getReader() because body.getReader doesn’t exist in node-fetch.
Related to the RevertError, I tried reproducing your error locally and it didn’t fail for me. Which forc version are you using to build your contract? It should be version 0.50.0.
Also, you’ve got a bug in { valueBefore }, it should be { value } because that’s the name of the return object’s property.
Hey thanks again for the hint, I checked I’m on 0.49.2.
When I run fuelup update, it says I already have the latest.
latest updated
updated components:
Hmm, I’m kinda stumped here. Perhaps you did something in-between that’s causing this issue because I’m able to interact with the equivalent contract normally, both with bytecodes generated with forc 0.49.2 and 0.50.0 on fuel-core 0.21.1 which is the beta-5 version of fuel-core.
Just to unblock you, given that you’re using the TS SDK, we do have a quickstart template that you can use. Could you please follow its instructions and let us know how it went?
Thanks again for your suggestion @nedsalk. I tried the below steps:
Use a very simple contract, deploy it and read test_function through await contract.functions.test_function().simulate(); it works, I got value true in the response.
Take the example contract from Quickstart Contract | Fuel Docs, deploy it then read the count through await contract.functions.count().simulate();, it doesn’t work and I got error “The script reverted with reason Unknown, cause: ScriptResultDecoderError: Execution of the script associated with contract xxx resulted in a non-zero exit code: 1”
I figured it out, the revert is due to uninitialized storage value, despite I’ve used the initializer as below:
storage {
counter: u64 = 0,
}
If I directly try to perform a storage.counter.read(), I get The transaction reverted with an unknown reason: 0. However I added an init method which explicitly set the storage counter value to 42, after that I’m able to retrieve its value correctly.
To summarize, what I did is:
Add a new method in the contract:
fn constructor() {
storage.counter.write(42);
}
Deploy the contract
Call the constructor method to explicitly write to the storage.
Read the storage afterwards and get a value 42 as expected.
@nedsalk Can you help me understand why the initial value of the storage can’t be read?
Calling the get method before the increment method
And it worked. I can’t reproduce the problem you’re facing. The sway playground is using forc 0.60.0, deploying on the sepolia testnet which is using fuel-core 0.27.0, and using fuels 0.88.1 for the typescript code.
The initial value of the storage can be read via this.
A lot of development has happened since this issue arose and you might be using outdated versions of all three dependencies listed above.
The quickstart guide I gave you previously also got revamped and now we’ve got a CLI tool that you can use. Could you please try that and see if you’re still facing issues? Please take note that you have to set your forc and fuel-core versions via fuelup. After install of fuelup, you can do this one-liner to set it up: