CDN Read
Explains how to read the smartcontract configuration using Seascape SDK.
In order to read the Smartcontract ABI and Smartcontract address of the particular project, Seascape SDK uses Seascape CDN. While CDN Write module writes the config onto the Seascape CDN, the CDN Read module does the opposite of CDN Write module. CDN Read module fetches the configuration.
In order to use the CDN Read to get the smartcontract configuration, the developer has to know the project name, project environment.
In order to read from CDN Read, we must first redownload the Config. This happens only once.
We do it by calling initConfig() method. So, at the index.js initiate the Configuration.
import { CdnRead, ConfigPath } from "seascape";
// This is the main.ts an entry point of the backend that could
// - expose the API
// - connect to the database
// - initiate the local privatekeys
(await () => {
let projectParams = {project: "greeter", env: "beta"} as ConfigPath;
const empty = true;
let initiated = await CdnRead.initConfig(projectParams, empty);
if (initiated === false) {
console.error("Failed to fetch the configuration");
// main code...
The initConfig() accepts two parameters:
  • configPath (ConfigPath type) - required. The project and environment names.
  • empty (Boolean type) - optional, by default it's false. This parameter is used, when there is no smartcontract configuration according to the configPath. If there is a smartcontract configuration, then this parameter doesn't play any role. When Seascape CDN returns 404 Not Found, If empty is false, then CDN Read module will return false, as well as will print the error on error output. If the empty is true, then CDN Read module will return true, as well as initiate the default config which is empty.
The initiated configuration is stored in a global file: global.seascapeCdnConfig.
Once you have the global smartcontract config, you can fetch the smartcontract address as well as the abi of the contract.

Fetching smartcontract address

Use CdnRead.contractAddress(networkId: string, type: string, name: string)
It returns false, in any error case as well as it prints the error reason on error output.
It returns smartcontract address as a string, if it was successful.
Here is the parameters that it accepts:
  • networkId (string) - network id, where the smartcontract was deployed.
  • type (string) - category of the smartcontract, for example "erc20", "nfts", "game" etc. You should discuss it within your team how the smartcontracts are categorized.
  • name - the name of the smartcontract, usually it matches to the smartcontract's filename without the .sol extension.

Fetching smartcontract ABI

If you know the smartcontract name, then you can get the ABI information with the two requests:
CdnRead.abiConfig(name: string)
abiConfig returns AbiConfig object. The AbiConfig object has only one parameter: "version".
If there is no AbiConfig for the file, the abiConfig method will return the default AbiConfig with the default version value as 0.
  • name (string type) - required, is the name of the smartcontract. Usually it matches to the smartcontract name without .sol extension.
Once you have the AbiConfig, you can call the CdnRead.abi(name: string, config: AbiConfig) method.
The CdnRead will either return false, and output the error reason on the standard error. Otherwise it will return the ABI object.
// abiConfig is returned by CdnRead.abiConfig()
let abi = await CdnRead.abi('Greeter', abiConfig);
Copy link
On this page
Fetching smartcontract address
Fetching smartcontract ABI