Git Product home page Git Product logo

contract-template's Introduction

Smart Contract template

Smart contracts on VSC are compiled using AssemblyScript. This is a template project to get started writing smart contracts.

General Tips

For smart contract specific functionality, use the @vsc.eco/sdk/assembly module. For more general functionality, use the assemblyscript/std/assembly module. It contains useful data structures and functions that are usable in the smart contract. Note: If you see a missing module error during testing, it is likely that that part of the AssemblyScript standard library is not yet supported by VSC contracts.

Scripts

  • deploy: compiles & deploys a release build of the smart contract. Note: Ensure both HIVE_ACCOUNT_USERNAME and HIVE_ACCOUNT_ACTIVE_PRIVATE_KEY are set in your environment or in the .env file in the root of this project. They are both used to deploy the smart contract via a custom-json operation on Hive.
  • asbuild:debug: compiles a debug build of the smart contract. This is used in both test environments. Used to manually compile this for the code changes to be reflectled in the tests.
  • asbuild:debug-live: observes the changes in the smart contract and compiles a debug build on changes. This is best used in conjunction with test:debug for a small feedback loop.
  • test: runs the tests using jest. This is good for CI or running individual tests without debugging support.
  • test:debug: runs the tests using mocha & vite. This runs tests in the browser with sourcemap support allowing breakpoint debugging your smart contract with the original AssemblyScript source code.

Folder structure

  • assembly: where your smart contract source code lives
  • build: where the build artifacts are placed
  • scripts: where scripts live
  • tests: where your tests live

Files that should NOT be touched

These files will be moved to a separate library at some point and are not intended to be modified for contract development. Modifications may break your tests. You have been warned.

  • assembly/tsconfig.json
  • index.html
  • vite.config.ts
  • .swcrc
  • asconfig.json
  • jest.config.cjs
  • tsconfig.json
  • tests/debug.ts
  • tests/mocks.ts
  • tests/vite-env.d.ts
  • scripts/deploy.ts

Testing Apperatice

There is a file tests/mocks.ts, which contains all the utilities for testing. These utilities are listed below.

  • reset(): Resets the state of the smart contract and returns it to the initial state. In the example tests/index.ts, this is called before each test, but you can call it manually if you want to reset the state during a test. It is also possible to call reset() manually in your test suite without using beforEach(), but this is advanced usage and not recommended due to the higher likelihood of bugs from the running order of tests.
  • contract: The instance to your compiled smart contract with type safety.
  • stateCache: A mock of the persistent state of the contract. This is cleared after each reset().
  • contractEnv: Envirnoment variables available to the contract.
  • logs: An array of logs emitted by the smart contract since the last reset().
  • error: The last error thrown by the smart contract since the last reset().
  • IOGas: The total gas used by the smart contract since the last reset().
  • memory: Raw WebAssembly Memory your smart contract can access. This is not persisted between contract calls and is cleared after each reset().

Libraries

The following libraries are supported by VSC smart contracts.

  • @vsc.eco/sdk/assembly: The VSC smart contract SDK. This library serves general purposes and provides various smart contract specific functionality.
  • as-bigint: A very handy library for simple arithmetic with large numbers. Also useful when an operation like taking the power of a number is required (** operator), as assemblyscript does not natively support this.

contract-template's People

Contributors

geo25rey avatar vaultec81 avatar techcoderx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.