#Get contract spec for SAC instance

1 messages · Page 1 of 1 (latest)

prisma saffron
#

I have this function that I use to get contract specs, but sometimes it get's called with the contract ID for a SAC instance. I'm not super sure, but I think this fails because SAC instances don't have ledger entries for contract data in the same way as a sep41 token that is not a SAC.

Can anyone confirm that's correct and/or how to get contract spec when the contract can be either a SAC instance of a sep41 token?

https://github.com/stellar/freighter-backend/blob/f07cc2339321a3981f287501112b8a403d433d8f/src/helper/soroban-rpc/index.ts#L276

prisma saffron
#

Yeah so it looks like the ScContractInstance for a token has the wasm hash like this

ChildStruct {
  _attributes: {
    executable: ChildUnion {
      _switch: [ChildEnum],
      _arm: 'wasmHash',
      _armType: [Opaque],
      _value: <Buffer 64 7b 6b c0 8c 02 3d 7c a1 89 19 2a 7e 24 a9 f0 52 6b ca 1a d0 c7 68 a3 6f 78 70 74 75 5f 69 f0>
    },
    storage: [
      [ChildStruct],
      [ChildStruct],
      [ChildStruct],
      [ChildStruct],
      [ChildStruct],
      [ChildStruct]
    ]
  }
}

and the SAC instance doesn't

ChildStruct {
  _attributes: {
    executable: ChildUnion {
      _switch: [ChildEnum],
      _arm: [class Void extends XdrPrimitiveType],
      _armType: [class Void extends XdrPrimitiveType],
      _value: undefined
    },
    storage: [ [ChildStruct], [ChildStruct], [ChildStruct] ]
  }
}

but not sure if there is something to key off of to know SAC instance vs token?

prisma saffron
#

welp I forgot that I had already come across this before but for others it's

executable.switch().name ===
      xdr.ContractExecutableType.contractExecutableStellarAsset().name
dusk granite
#

I was able to get a contract instance for a sac during testing and chatted about this with someone a couple weeks ago. Was gonna link u to the conversation but now nope can't find it. Must have been in a dm

#

Ah u got it

prisma saffron
#

hey thanks yeah I actually found the answer in code i had written at some point in the past 😭 😄