Seascape Network
EN
EN
  • Welcome to Seascape
  • Guides
    • How to use the Scape Store Swapping Feature
    • How to Play Profit Circus
    • Guide to NFT Brawl
    • Guide to Staking Saloon
    • Guide to Scape Forum
    • Guide to Zombie Farm
    • Bridge Your MSCP between MOVR and BSC
    • Guide to join the pCWS Pools and NFT Trading
  • SMARTCONTRACTS
    • Addresses
      • Lighthouse
      • Changelog
    • Installation
    • Seascape NFT (SCAPES)
    • Crowns (CWS) token
  • Game for Developers
    • API Urls
    • Seascape Nft
    • Game 2: NFT BRAWL
      • Leaderboard
    • Game 5: Zombie Farm
      • Glossary
      • Reward categories
      • Option categories
      • API call order
  • Scape Store (Marketplace)
    • Config
    • Nft Swap
    • RPC backend
    • Smartcontract Changelog
  • API changelog
  • Seadex
    • Intro
    • Local deployment
    • Addresses
    • Managing Token
      • Add supported token to Factory
  • Lighthouse (IDO)
    • API
    • Smartcontrontracts
      • Tiers
    • Installation
  • Seascape SDK
    • Intro
    • Installation
    • Features
      • Shared Smartcontract Parameters
        • Configuration Format
        • Seascape CDN Config
        • CdnWrite
          • Truffle Framework
          • Hardhat Framework
          • Non-framework update
        • CDN Read
      • Server Proof
        • Smartcontract Data
        • Proof of Server
Powered by GitBook
On this page
  • Fetching smartcontract address
  • Fetching smartcontract ABI

Was this helpful?

  1. Seascape SDK
  2. Features
  3. Shared Smartcontract Parameters

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");
        process.exit(1);
    }

    // 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)

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);

PreviousNon-framework updateNextServer Proof

Last updated 2 years ago

Was this helpful?

abiConfig returns object. The AbiConfig object has only one parameter: "version".

AbiConfig