#How to use wasm hash to deploy a soroban contract by JS SDK?

5 messages · Page 1 of 1 (latest)

proud lantern
#

Hi, eveyrone.
Currently, I have a exist wasm hash: 7e907b4367286769a6f0b1b13c0998dce0d678c2582c184210061f254b59956b

Via the command line I can deploy successfully:

$stellar contract deploy \
--wasm-hash 7e907b4367286769a6f0b1b13c0998dce0d678c2582c184210061f254b59956b \
--source alice \
--network testnet \
> -- --admin GBJIR3NUDYCX2TNHBTGPWIEUT5DNGBEUZHYCNY2GNECZRBST3M2II73U

✅ Deployed!
CCYJRY2UGDSNKYS3INOIYTKWNWH2Z53E76UUJAZZOHAAI2ZNNLA5KFFB

However, when I deployed it via the JS SDK, I encountered the following error:

/xxx/node_modules/@stellar/js-xdr/lib/webpack:/XDR/src/union.js:26
      throw new TypeError(`${armName} not set`);
            ^
TypeError: bytes not set
    at ChildUnion.get (/xxx/node_modules/@stellar/js-xdr/lib/webpack:/XDR/src/union.js:26:13)
    at ChildUnion.get [as bytes] (/xxx/node_modules/@stellar/js-xdr/lib/webpack:/XDR/src/union.js:163:25)

This is part of my code:

// Build Operation
 const operation = Operation.createCustomContract({
    wasmHash: Buffer.from(
      '7e907b4367286769a6f0b1b13c0998dce0d678c2582c184210061f254b59956b',
      'hex',
    );
    address: Address.fromString(xxx),
    salt,
    constructorArgs: [xdr.ScVal.scvAddress(scAddress)],
  });

  const transaction = new TransactionBuilder(account, {
    fee: BASE_FEE,
    networkPassphrase: Networks.TESTNET,
  })
    .addOperation(operation)
    .setTimeout(30)
    .build();


  const tx = await rpcServer.prepareTransaction(
    transaction,
  );
  tx.sign(sourceKeypair);
  const response = await horizonServer.submitTransaction(tx);

How to solve this problem?

sweet onyx
#

Please I check again, you need to do this first

sweet onyx
#

const wasmHashBuffer = Buffer.from(
"7e907b4367286769a6f0b1b13c0998dce0d678c2582c184210061f254b59956b",
"hex"
);

I see you have that already so it should work actually

wary haven
proud lantern
#

Thanks, everyone,
The testnet is now available, but the mainnet awaiting an upgrade to v22, so I cannot deploy to the mainnet right now.
So I think I can only wait for the mainnet upgrade