dappKit Documentation
  • About dappKit
  • Start building
    • Installation
    • How To Guides
      • Create a Web3Connection
      • Create an ERC20 Token
      • Create an ERC1155
      • Create an ERC721
      • Create your NFT Art Gallery
      • Create other Project
      • Create custom Object
    • Examples
  • Use Cases
  • How to Contribute
  • External Links
    • SDK Documentation
    • GitHub
  • Community
    • Discord Server
    • Support
Powered by GitBook
On this page
  1. Start building
  2. How To Guides

Create custom Object

A custom project is a project wich only depends on dappkit (and dappkit-launcher) to complement its own Solidity contracts.

PreviousCreate other ProjectNextExamples

Last updated 3 years ago

Dependencies

$ npm i -s @taikai/dappkit
$ npm i -g @taikai/dappkit-launchpad

@taikai/dappkit will be used to provide the user with proxies for common contracts, along with a Web3Connection, and @taikai/dappkit-launchpad will be responsible for transpiling your custom contract into something understandable by @taikai/dappkit.

Compiling your contracts

Both truffle and hardhat will provide a ContractName.json file wich holds the ABI and bytecode for the contract

Truffle

$ npm i -g truffle
$ truffle compile

Hardhat

$ npx install --save-dev hardhat
$ npx hardhat compile

Transpiling and using your custom contract

$ dk-transpile -f "path/to/ContractName.json"

Depending on your configuration (and contract) this will output a extension of the class, with the methods loaded in, and with the name of the file matching the name of the contract.

Deploying the custom contract

import {CustomContract} from './path/to/CustomContract';
const customContract = new CustomContract({web3Host: 'http://localhost:1337', privateKey: '0xPrivateKey'});

customContract.web3Connection.start();
customContract.loadAbi();

const tx = await customContract.deployJsonAbi('arg1', 'arg2'/*, arg3, arg4, ...etc*/);
console.log('Deployed contract; Address: ', tx.contractAddress);

Using the custom contract

const customContract = new CustomContract({web3Host: 'http://localhost:1337', privateKey: '0xPrivateKey'});

customContract.start();

// Get a value on the contract
const receipt = await customContract.CustomMethod('arg1'/*, 'otherArgument', ...etc */);

// Change a value on the contract
const receipt2 = await customContract.OtherCustomMethod('newValue'/*, 'otherArgument', ...etc */)

Costumizing a custom contract proxy

@taikai/dappkit-launchpad made a custom proxy from the coded that was provided, but this proxy can be futher customized - by hand.

Just open the ./path/to/CustomContract and add more functions, or add a customization to the super.start that loads information for a custom API:

/* ... erased code for brevity */
async function start() {
  const data = await fetch('http://localhost:1337/api/health').then(() => true).catch(() => false)
  if (!data)
    throw Error('Something happened!!!11');
  return super.start()
}
/* erased code for brevity... */
Model