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

Commit

Permalink
Update WASM retrieval tutorial (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Oct 26, 2023
1 parent 184791c commit 7289016
Showing 1 changed file with 9 additions and 20 deletions.
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");

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

0 comments on commit 7289016

Please sign in to comment.