deployContract

Deploys a new contract from a given factoryContractId

As with all new SDK api methods, this call should be wrapped in execute and passed a signing method

deployContract(args: DeployContractArgs): NearContractCall

deployContract takes a single argument of type DeployContractArgs

export type DeployContractArgs = {
    //the contract factory used to deploy the contract
    //if not provided defaults to the mintbase testnet contract factory: 'mintspace2.testnet'
    factoryContractId?: string;
    //name for the contract, this should be unique within the factory
    name: string;
    //wallet id of the intended owner
    ownerId: string;
    metadata: {
      symbol: string;
      //if nothing is provided will default to the mb default logo
      icon?: string;
      //will default to null
      baseUri?: string;
      //will default to null
      reference?: string;
      //will default to null
      referenceHash?: string; 
    };
  };

React example

Example usage of deployContract method in a hypothetical React component:

DeployContractComponent.ts
import { useState } from 'react';
import { useWallet } from '@mintbase-js/react';
import { execute, deployContract , DeployContractArgs } from '@mintbase-js/sdk';


export const DeployContractComponent = ({ name, owner, contractId, symbol }:DeployContractArgs):JSX.Element => {
  
  const { selector } = useWallet();

  const handleDeployContract = async (): Promise<void> => {
    const wallet = await selector.wallet();

    await execute(
        //because no contract factory id is provided it defaults to 'mintspace2.testnet'
        {wallet},
        deployContract({
          name: name,
          ownerId: owner,
          metadata: {
            symbol: symbol
          }
        })
      )
  }

  return (
    <div>
      <button onClick={() => handleDeployContract()}>
        DeployContract with name= {name} and owner= {owner}
      </button>
    </div>
  );
};

Last updated