# dfinance

> Set of tools for dApp development on dfinance

Latest version **0.0.8** (published 2020-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install dfinance
pnpm add dfinance
yarn add dfinance
bun add dfinance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2020-12-23 |
| First published | 2020-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Damir Shamanaev |
| Maintainers | rspiridonov |
| Keywords | dfinance, defi, move, libra, compiler, smartcontract, xfi |

## Links

- npm: https://www.npmjs.com/package/dfinance
- npm.io page: https://npm.io/package/dfinance

## Dependencies (5)

- [lcs-js](https://npm.io/package/lcs-js.md) 0.0.3
- [request](https://npm.io/package/request.md) ^2.88.2
- [cosmos-lib](https://npm.io/package/cosmos-lib.md) ^1.1.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.1
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.9

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2020-12-23

## README

# dfinance js

The most effective way to work with dfinance smart contracts on NodeJS.

## Examples

```
npm install dfinance
```

### Search contract events

```JavaScript

const DFI = require('dfinance');
const dfi = new DFI('https://rest.testnet.dfinance.co/');

(async () => {

    const txSearch = await dfi.tracker.track({

        // main search params
        sender: 'wallet12tg20s9g4les55vfvnumlkg0a5zk825py9j0ha',
        action: 'execute_script',
        module: 'vm',
        // Search fromBlock, toBlock
        // Also you can use: {block: value}
        // to search in specific block
        block: [0, 200000],

        // vm specific params
        vm: {
            module: '0x1::Account',
            event: '0x1::Account::ReceivedPaymentEvent'
        },

    });

    console.log(JSON.stringify(txSearch, null, 4));
})();
```

### Compile scripts/modules and execute them!

```JavaScript
const mnemonic = '...'; // PASTE HERE!
const DFI = require('dfinance');
const dfi = new DFI('https://rest.testnet.dfinance.co/');

(async () => {

    const wallet = new dfi.Wallet(mnemonic);
    const addr   = wallet.address;
    const script = await dfi.compile(addr, `
        script {
            use 0x1::Account;
            use 0x1::Coins::ETH;

            fun main(acc: &signer) {
                Account::pay_from_sender<ETH>(
                    acc,
                    0x1,
                    100000
                )
            }
        }
    `);

    const gas = '500000'; // 200k-300k is enough
    const account = await dfi.api.getAccount(addr);

    // also you can .publishModule
    const execScriptTx = dfi
        .tx({account, wallet, gas})
        .executeScript(script.code);

    const res = await dfi.api.broadcastTx(execScriptTx, 'block');

    console.log(res);

})();
```

### Multi script publish + arguments

```JavaScript
const mnemonic = '...'; // PASTE HERE!
const DFI = require('dfinance');
const dfi = new DFI('https://rest.testnet.dfinance.co/');

(async () => {

    const wallet = new dfi.Wallet(mnemonic);
    const addr   = wallet.address;
    const script = await dfi.compile(addr, `
        script {
            use 0x1::Account;
            use 0x1::XFI::T as XFI;

            fun main(
                account: &signer,
                payee: address,
                amount: u128
            ) {
                Account::pay_from_sender<XFI>(
                    account,
                    payee,
                    amount
                );
            }
        }
    `);

    const gas = '500000'; // 200k-300k is enough
    const account = await dfi.api.getAccount(addr);
    const tx = dfi
        .tx({account, wallet, gas})
        .multi()
        .executeScript(script.code, DFI.scriptArg([
            // &signer should never be passed!
            ['address', 'wallet12tg20s9g4les55vfvnumlkg0a5zk825py9j0ha'],
            ['u128', '100000000']
        ]))
        .executeScript(script.code, DFI.scriptArg([
            ['address', '0x1'],
            ['u128', '1000']
        ]))
        // .publishModule or .executeScript is also available here!
        .combine();

    const res = await dfi.api.broadcastTx(execScriptTx, 'block');

    console.log(res);

})();
```

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