#Help with ScMapEntry in js-soroban-client

2 messages · Page 1 of 1 (latest)

glass pendant
#

How can I create a custom struct using scMap, is this the correct way?:

  const organizationScVal = SorobanClient.xdr.ScVal.scvMap([
    new SorobanClient.xdr.ScMapEntry({
      key: SorobanClient.xdr.ScVal.scvSymbol("id"),
      val: SorobanClient.xdr.ScVal.scvBytes(Buffer.from(organization.id)),
    }),
    new SorobanClient.xdr.ScMapEntry({
      key: SorobanClient.xdr.ScVal.scvSymbol("admin"),
      val: SorobanClient.xdr.ScVal.scvAddress(
        SorobanClient.xdr.ScAddress.scAddressTypeAccount(
          SorobanClient.xdr.PublicKey.publicKeyTypeEd25519(
            SorobanClient.StrKey.decodeEd25519PublicKey(organization.admin)
          )
        )
      ),
    }),
  ]);
fiery otter
#

Yup! Soroban structs are represented as ScVal Maps, the structure can be found by inspecting the WASM of whatever contract defines the struct you are trying to create with the Soroban CLI:

soroban contract inspect --wasm /path/to/wasm

Also, you can get the ScVal Address from a public key in a slightly easier manner ->

new Address(publicKey).toScVal()