Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Update WASM retrieval tutorial JavaScript code #627

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions api/methods/getLedgerEntries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ print(
##### JavaScript

```javascript
const { xdr } = require("soroban-client")
const { Address, xdr } = require("soroban-client");

function getLedgerKeyContractCode(contractId) {
let ledgerKey = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: xdr.ScAddress.scAddressTypeContract(contractId),
contract: new Address(contractId).toScAddress(),
key: new xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent(),
bodyType: xdr.ContractEntryBodyType.dataEntry(),
durability: xdr.ContractDataDurability.persistent()
})
);

Expand All @@ -230,7 +230,7 @@ function getLedgerKeyContractCode(contractId) {

console.log(
getLedgerKeyContractCode(
"af9a2527e3b3b5571d63b0246ba32b7d31a5323766df7c60dfc0b3e3ba6fdf23"
"CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE"
)
)
// OUTPUT: AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA==
Expand Down Expand Up @@ -304,30 +304,19 @@ print(
##### JavaScript

```javascript
const { xdr } = require("soroban-client")
const { xdr } = require("soroban-client");
ElliotFriend marked this conversation as resolved.
Show resolved Hide resolved

function getLedgerKeyWasmId(contractCodeLedgerEntryData) {

let entry = xdr.LedgerEntryData.fromXDR(
const entry = xdr.LedgerEntryData.fromXDR(
contractCodeLedgerEntryData,
"base64"
);

let instance = new xdr.ScContractInstance({
executable: entry.contractData()
.body()
.value()
.val()
});
const instance = entry.contractData().val().instance();

let ledgerKey = xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({
hash: xdr.ContractExecutable.contractExecutableWasm(instance.executable())
.wasmHash()
.instance()
.executable()
.wasmHash(),
bodyType: xdr.ContractEntryBodyType.dataEntry()
hash: instance.wasmHash()
})
);

Expand Down