@waves/ts-contract
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

ts-contract

Create strongly typed invokes for your ride contracts

Installation

npm i @waves/ts-contract

Contract definitions and Invoke script transaction

Lest take a look on a simple contract definition:

interface myContract {
  foo(value: String)
}

Every interface method should correspond to @Callable(i) function in your .ride smart contract. In this case the contract is pretty simple:

{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}

@Callable(i)
func foo(value: String) = {
    WriteSet([
        DataEntry("data", value.size())
    ])
}

You can use it to get invoke transaction builder:

import { contract } from '@waves/ts-contract'
const { foo } = contract<myContract>()('3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn')
foo('hello').invoke('seed') // => IInvokeScriptTransaction

In case your application use multiple contracts with the same code you can specify dApp address and when calling invoke itself

import { contract } from '@waves/ts-contract'
const { foo } = contract<myContract>()()
foo('hello')
  .invoke('seed', { dApp: '3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn' })
  // => IInvokeScriptTransaction

Generate code

To auto generate definitions run the following command in project folder terminal:

npx @waves/ts-contract 3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn ./myContract.ts

Where 3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn is deployed dApp address.

Or if you want to generate code from .ride file call:

npx @waves/ts-contract ./src/myContract.ride ./myContract.ts

The generated myContract.ts file will look like this:

import { ByteVector, contract } from '@waves/ts-contract'

export interface myContract {
  foo(value: String | Number | Boolean | ByteVector)
}
export const { foo } = contract<myContract>()('3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn')

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.191latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.191
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @waves/ts-contract

Weekly Downloads

1

Version

0.0.19

License

MIT

Unpacked Size

36.2 kB

Total Files

20

Last publish

Collaborators

  • enichegovskiy
  • xrtm000
  • bodrych
  • msmolyakov-waves
  • vsuharnikov
  • gakhramanov
  • tsigel
  • ebceu4
  • vba2000
  • wavesadmin
  • dvshur
  • jlewka
  • kozhevnikov.peter
  • axepuff
  • okanishcheva
  • vladislav.petushkov