# @saturn-chain/smart-contract

> Usage: ```sh npm i --save @saturn-chain/smart-contract ``` Includes typescript types declaration

Latest version **2.0.4** (published 2025-12-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @saturn-chain/smart-contract
pnpm add @saturn-chain/smart-contract
yarn add @saturn-chain/smart-contract
bun add @saturn-chain/smart-contract
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2025-12-19 |
| First published | 2021-11-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 120.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | guenoledc |

## Links

- npm: https://www.npmjs.com/package/@saturn-chain/smart-contract
- npm.io page: https://npm.io/package/@saturn-chain/smart-contract

## Dependencies (3)

- [mitt](https://npm.io/package/mitt.md) ^3.0.1
- [viem](https://npm.io/package/viem.md) ^2.43.1
- [@saturn-chain/dlt-tx-data-functions](https://npm.io/package/@saturn-chain/dlt-tx-data-functions.md) ^2.0.2

## Recent versions

- 2.0.4 (latest) — 2025-12-19
- 2.0.3 — 2025-12-18
- 2.0.2 — 2025-12-18
- 2.0.1 — 2025-12-17
- 1.0.23 — 2025-03-16
- 1.0.22 — 2025-02-25
- 1.0.21 — 2025-02-25
- 1.0.20 — 2025-02-25
- 1.0.19 — 2022-07-27
- 1.0.18 — 2022-06-25
- 1.0.17 — 2022-05-25
- 1.0.16 — 2022-04-13
- 1.0.15 — 2022-04-08
- 1.0.14 — 2022-04-08
- 1.0.13 — 2022-04-07
- … 13 more at https://npm.io/package/@saturn-chain/smart-contract/versions

## README

# smart-contract: takes a set of compiled solidity contracts to execute them in JS

Usage: 
```sh
npm i --save @saturn-chain/smart-contract
```
Includes typescript types declaration


## Documentation

```typescript
import { SmartContracts } from "smart-contract";
// combined.json is the result of the solidity compilation with a command line like
// solc -o contracts --combined-json abi,bin --overwrite src/*.sol
const SC = SmartContracts.load(require("contracts/combined.json"));

// Fictive implementation of the EthProviderInterface
import { Impl } from "impl-function";
const intf = new Impl();

const MyContract = SC.get("MyContract");

// deploy the smart contract into the chain using the interface implementation
// uses the newi() returned function to receive the compiled data 
const instance = await MyContract.deploy(intf.newi({}), param1, param2);
// display the address where the smart contract instance has been deployed
console.log("Created instance", instance.deployedAt);

// creaate a contract instance of an already deployed smart contract at a given address
const instance2 = MyContract.at("0x123...999")

// call a function of the instance (just reading the chain state)
// solidity MyContract has a function totalSupply with no parameter
const value = await instance.totalSupply(intf.call());

// send a transaction to the chain to be mined
// solidity MyContract has a transfer(amount, recipient) function
const tx = await instance.transfer(intf.send({maxGas: 100000}), 1000, "0x123...999");

// get historical events
// solidity MyContract has an event Transfer(from, to, amount)
instance.events.Transfer(intf.get({
  fromBlock: 100
}), {from:"0x123...999"});

// subscribe to all events 
const ev = instance.allEvents(intf.sub, {})
// register a log handler
.on("log", console.log)
// register the error handler
.on("error", err=>{
  console.error(err);
  // trigger the end of the subscription, no more event received
  ev.removeAllListeners();
  })
```

---
_Source: https://npm.io/package/@saturn-chain/smart-contract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
