I would like to figure out how to get a list of all the smart contracts account ids and WASM blobs that have been uploaded to a specific parachain, ideally into python using the substrate interface. This picture shows that contracts is one of the options under selected chain state, but when I go to polkadotjs I don't see the contracts option.

1 Answer 1


I am sharing with you the code about how to do it using PolkadotJS. Using python should be calling the same functions.

First connect to the parachain you want to query

  const wsProvider = new WsProvider('ws://"');
  const api = await ApiPromise.create({ provider: wsProvider });

After get all the contracts (where you will get the account ids you are looking for) calling the extrinsic contractInfoOf but instead of specifying and account ID querying all the entries.

  const contracts = await api.query.contracts.contractInfoOf.entries();

Finally go through all the contracts you got, parse the data to get the account ID and the codeHash.

You are going to use the codeHash to call the extrinsic codeStorage in order to get the code.

    for (const contract of contracts){
      const accountId = contract[0].toHuman()[0];

      const codeHash = contract[1].toHuman().codeHash;
      const codeStorage = await api.query.contracts.codeStorage(codeHash);
      const code = codeStorage.toHuman().code;

      console.log(`Accountid: ${accountId} - Code: ${code}`);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.