Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SDK errors when a valid config or network is not provided to a given SC class constructor #82

Open
paulo-ocean opened this issue Dec 13, 2024 · 0 comments · May be fixed by #84
Open
Assignees

Comments

@paulo-ocean
Copy link
Contributor

paulo-ocean commented Dec 13, 2024

Many times i see that "config" (from ConfigHelper) object is not defined (its null)
Because when we are calling certain classes that extend from SmartContract, like new NFTFactory(...) calls for instance, we are neither providing a valid config param, neither providing the network param ... without this info..
This line (on SDK SmartContract class):
this.config = config || new ConfigHelper().getConfig(network)
will resolve to null. Both config and network params are optional, but in reality we need to have one or the other...
One example of the wronng usage is on the src->helpers -> createAsset function

...
const nftFactory = new NftFactory(config.nftFactoryAddress, owner);
...

Bellow is the abstract class constructor on the SDK...

/**
   * Instantiate the smart contract.
   * @param {Signer} signer The signer object.
   * @param {string | number} [network] Network id or name
   * @param {Config} [config] The configuration object.
   * @param {AbiItem[]} [abi] ABI array of the smart contract
   */
  constructor(
    signer: Signer,
    network?: string | number,
    config?: Config,
    abi?: AbiItem[]
  ) {
    this.signer = signer
    this.config = config || new ConfigHelper().getConfig(network)
    this.abi = abi || this.getDefaultAbi()
  }

Note the "no config found" message bellow for the "undefined" network. When this happens config is null.
Some operations require multiple calls to getconfig() and this can lead to strange issues
Screenshot from 2024-12-18 09-14-43

@paulo-ocean paulo-ocean self-assigned this Dec 16, 2024
@paulo-ocean paulo-ocean linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant