# Failed to deploy contract using typescript sdk

**URL:** <https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440>\
**Category:** TypeScript SDK\
**Created:** [February 25, 2024, 9:59am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440 "2024-02-25T09:59:10Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 25, 2024, 9:59am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/1 "2024-02-25T09:59:10Z")

</div>

SDK version: fuels@0.74.0  
nodejs version: v20.11.1  
testnet version: beta-5  
environment: MacOS 11.6.7

Steps to reproduce:

1. Follow [Quickstart Contract | Fuel Docs](https://docs.fuel.network/docs/intro/quickstart-contract/) to build contract byte code & ABI.
2. Use the following code to deploy contract:

```auto
    const factory = new ContractFactory(byteCode, abi, wallet);
    const { minGasPrice: gasPrice } = wallet.provider.getGasConfig();
    const contract = await factory.deployContract({ gasPrice });
    console.log(`${wallet.address.bech32Address} deployed contract ${contract.id}`);
    console.log(JSON.stringify(contract));

```

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)

Node.js v20.11.1

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 25, 2024, 5:27pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/2 "2024-02-25T17:27:52Z")

</div>

Hi @yuduan0220, thanks for the report. There is a [PR](https://github.com/FuelLabs/fuels-ts/pull/1793) that will fix this error.

---

<div class="post-metadata">

**Author:** ![Dhaiwat10](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/dhaiwat10/32/1283_2.png) [@Dhaiwat10](https://forum.fuel.network/u/Dhaiwat10)\
**Post date:** [February 25, 2024, 6:05pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/3 "2024-02-25T18:05:12Z")

</div>

Also, please try using `0.73.0` as mentioned in the guide, and try again

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 25, 2024, 6:06pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/4 "2024-02-25T18:06:38Z")

</div>

@Dhaiwat10 I tried 0.73.0 and got the same error.

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 25, 2024, 6:07pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/5 "2024-02-25T18:07:28Z")

</div>

Thanks @nedsalk is it gonna be included in 0.75.0?

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 26, 2024, 4:57pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/6 "2024-02-26T16:57:21Z")

</div>

@yuduan0220 You’re welcome! Yes, it’ll be included in that release. The PR for the release is [here](https://github.com/FuelLabs/fuels-ts/pull/1781).

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 27, 2024, 3:59pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/7 "2024-02-27T15:59:38Z")

</div>

I downloaded 0.75.0 and got a different error now:

fuel/node\_modules/@fuel-ts/account/dist/index.js:1065  
this.stream = response.body.getReader();  
TypeError: response.body.getReader is not a function

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 27, 2024, 4:26pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/8 "2024-02-27T16:26:50Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 28, 2024, 8:54am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/9 "2024-02-28T08:54:45Z")

</div>

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.

The code is really simple, snippet below:

```auto

async function deploy(byteCode, abi, wallet) {
    const factory = new ContractFactory(byteCode, abi, wallet);
    const { minGasPrice: gasPrice } = wallet.provider.getGasConfig();
    const contract = await factory.deployContract({ gasPrice });
    console.log(`${wallet.address.bech32Address} deployed contract ${contract.id}`);
    console.log(JSON.stringify(contract));
    // interact with deployed contract

    await interact(contract.id, abi, wallet);
}

```

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 28, 2024, 9:25am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/10 "2024-02-28T09:25:26Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 28, 2024, 1:10pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/11 "2024-02-28T13:10:05Z")

</div>

Brilliant, @nedsalk I’ve upgraded to node v18 and removed global fetch override. I’m able to deploy the contract, thanks a ton!

However I’m seeing a second issue, when trying to read value from the deployed contract.

```auto
async function interact(id, abi, wallet) {
    const contract = new Contract(id, abi, wallet);
    const { valueBefore } = await contract.functions.count().simulate();
    console.log({valueBefore});
}

```

I got the error: “RevertError: The script reverted with reason Unknown”

The contract I deployed is very simple:

```auto
contract;

storage {
    counter: u64 = 0,
}

abi Counter {
    #[storage(read, write)]
    fn increment(input: u64);

    #[storage(read)]
    fn count() -> u64;
}

impl Counter for Contract {
    #[storage(read)]
    fn count() -> u64 {
        return storage.counter.read()
    }

    #[storage(read, write)]
    fn increment(input: u64) {
        let incremented = storage.counter.read() + input;
        storage.counter.write(incremented);
    }
}

```

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 28, 2024, 2:29pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/12 "2024-02-28T14:29:51Z")

</div>

Great, we’re moving forward!

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.

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 28, 2024, 3:08pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/13 "2024-02-28T15:08:41Z")

</div>

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:

- forc 0.49.2
- forc-explore 0.28.1
- forc-wallet 0.4.3
- fuel-core 0.22.0
- fuel-core-keygen 0.22.0

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [February 29, 2024, 7:50am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/14 "2024-02-29T07:50:29Z")

</div>

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](https://fuellabs.github.io/fuels-ts/guide/quickstart/) that you can use. Could you please follow its instructions and let us know how it went?

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [February 29, 2024, 3:49pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/15 "2024-02-29T15:49:10Z")

</div>

Thanks again for your suggestion @nedsalk. I tried the below steps:

1. 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.

```auto
contract;

abi MyContract {
	fn test_function() -> bool;
}

impl MyContract for Contract {
	fn test_function() -> bool {
		true
	}
}

```

1. Take the example contract from [Quickstart Contract | Fuel Docs](https://docs.fuel.network/docs/intro/quickstart-contract/), 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”

```auto
contract;
 
storage {
    counter: u64 = 0,
}
 
abi Counter {
    #[storage(read, write)]
    fn increment();
 
    #[storage(read)]
    fn count() -> u64;
}
 
impl Counter for Contract {
    #[storage(read)]
    fn count() -> u64 {
        storage.counter.read()
    }
 
    #[storage(read, write)]
    fn increment() {
        let incremented = storage.counter.read() + 1;
        storage.counter.write(incremented);
    }
}

```

---

<div class="post-metadata">

**Author:** ![keeplook](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/keeplook/32/2440_2.png) [@keeplook](https://forum.fuel.network/u/keeplook)\
**Post date:** [March 5, 2024, 8:28am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/16 "2024-03-05T08:28:21Z")

</div>

I also have this problem. Have you solved it

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [March 6, 2024, 1:56pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/17 "2024-03-06T13:56:36Z")

</div>

Nope, hasn’t heard back from the team yet. Keep me posted if you found something.

---

<div class="post-metadata">

**Author:** ![yuduan0220](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/yuduan0220/32/2201_2.png) [@yuduan0220](https://forum.fuel.network/u/yuduan0220)\
**Post date:** [June 5, 2024, 2:42pm UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/18 "2024-06-05T14:42:23Z")

</div>

I figured it out, the revert is due to uninitialized storage value, despite I’ve used the initializer as below:

```auto
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:

1. Add a new method in the contract:

```auto
fn constructor() {
    storage.counter.write(42);
}

```

1. Deploy the contract
2. Call the constructor method to explicitly write to the storage.
3. 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?

---

<div class="post-metadata">

**Author:** ![nedsalk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nedsalk/32/1867_2.png) [@nedsalk](https://forum.fuel.network/u/nedsalk)\
**Post date:** [June 11, 2024, 8:31am UTC](https://forum.fuel.network/t/failed-to-deploy-contract-using-typescript-sdk/4440/19 "2024-06-11T08:31:30Z")

</div>

Sorry for not addressing your comments earlier, this conversation slipped through.

I tried the simple counter example via [https://www.sway-playground.org/](https://www.sway-playground.org/) by:

1. Compiling and deploying the contract,
2. 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](https://docs.fuel.network/docs/fuels-ts/creating-a-fuel-dapp/) 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`](https://docs.fuel.network/guides/installation/). After install of `fuelup`, you can do this one-liner to set it up:

`fuelup toolchain new custom && fuelup component add forc@0.60.0 && fuelup component add fuel-core@0.27.0`.
