Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wavesenterprise/contract-core

Package Overview
Dependencies
Maintainers
7
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wavesenterprise/contract-core

Implements JS Contract SDK core functionality, rpc services, tools and utilities.

  • 1.2.11
  • latest
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

@wavesenterpise/contract-core

Implements JS Contract SDK core functionality, rpc services, tools and utilities.

Getting Started

Run following in command line:

npm i @wavesenterpise/contract-core

Create contract.ts as follows

import {
  Action,
  Contract,
  ContractMapping,
  ContractValue,
  IncomingTx,
  JsonVar,
  logger,
  Param,
  Params,
  Tx,
  Var,
  Block,
  Sender,
  BlockInfo,
} from '@wavesenterprise/contract-core'
import Long from 'long'

@Contract()
export default class #{contractName} {

  log = logger(this)

  @Var()
  counter!: ContractValue<number>

  @JsonVar()
  participants!: ContractMapping<UserData>

  @Action({ onInit: true })
  init(@Params() params: Record<string, unknown>) {
    this.counter.set(0)
    this.log.info('all params', params)
  }

  @Action({ preload: ['counter'] })
  async increment(@Tx() tx: IncomingTx, @Param('by') by: Long) {
    const { senderPublicKey, sender } = tx
    const counter = await this.counter.get()
    let participant = await this.participants.tryGet(senderPublicKey)
    if (!participant) {
      participant = {
        publicKey: senderPublicKey,
        address: sender,
        amount: 0,
      }
    }
    participant.amount += by.toNumber()
    this.counter.set(counter + by.toNumber())
    this.participants.set(senderPublicKey, participant)
  }
  
  async saveInfo(@Sender() sender: string, @Block() currentBlock: BlockInfo) {
    // 
  }
}

To initialize contract use:

import { initContract } from '@wavesenterprise/contract-core'

initContract({
  contractPath: __dirname + '/contract.js', // path to compiled contract
  concurrencyLevel: 1,
})

License

This project is licensed under the MIT License.

FAQs

Package last updated on 04 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc