# @lacchain/truffle-gas-model-provider

> Truffle Gas Model for LACChain Networks

Latest version **1.0.0** (published 2022-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lacchain/truffle-gas-model-provider
pnpm add @lacchain/truffle-gas-model-provider
yarn add @lacchain/truffle-gas-model-provider
bun add @lacchain/truffle-gas-model-provider
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-07-20 |
| First published | 2022-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 102.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sergio Ceron Figueroa |
| Maintainers | sergiocf |
| Keywords | etheruem, hd, mnemonic, provider, wallet, LACChain, LAC-NET, Gas-Model |

## Links

- npm: https://www.npmjs.com/package/@lacchain/truffle-gas-model-provider
- Repository: https://github.com/lacchain/truffle-gas-mode-provider
- Homepage: https://github.com/lacchain/truffle-gas-mode-provider#readme
- Issues: https://github.com/lacchain/truffle-gas-mode-provider/issues
- npm.io page: https://npm.io/package/@lacchain/truffle-gas-model-provider

## Dependencies (8)

- [@ethereumjs/tx](https://npm.io/package/@ethereumjs/tx.md) ^3.3.0
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^7.1.5
- [ethereum-protocol](https://npm.io/package/ethereum-protocol.md) ^1.0.1
- [ethereumjs-wallet](https://npm.io/package/ethereumjs-wallet.md) ^1.0.2
- [@ethereumjs/common](https://npm.io/package/@ethereumjs/common.md) ^2.4.0
- [web3-provider-engine](https://npm.io/package/web3-provider-engine.md) 16.0.3
- [ethereum-cryptography](https://npm.io/package/ethereum-cryptography.md) 1.1.2
- [@metamask/eth-sig-util](https://npm.io/package/@metamask/eth-sig-util.md) 4.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-07-20

## README

# @lacchain/gas-model-provider
Truffle Provider. Use it to sign transactions using the LACChain Gas Model.

## Install

```
$ npm install @lacchain/truffle-gas-model-provider
```

## Requirements
```
Node >= 12 
Web3 ^1.2.0
```

## General Usage

You can use this provider wherever a Web3 provider is needed, not just in Truffle. For Truffle-specific usage, see next section.

By default, the `GasModelProvider` will use the address of the first address that's generated from the mnemonic. If you pass in a specific index, it'll use that address instead.

### Instantiation

You can instantiate `gas-model-provider` with options passed in an object with
named keys. You can specify the following options in your object:

Parameters:

| Parameter           | Type | Default | Required | Description |
|---------------------| ---- | ------- | ----------- | -- |
| `mnemonic`          | `object\|string` | `null` | [ ] | Object containing `phrase` and `password` (optional) properties. `phrase` is a 12 word mnemonic string which addresses are created from. Alternately the value for mnemonic can be a string with your mnemonic phrase. |
| `privateKeys`       | `string[]` | `null` | [ ] | Array containing 1 or more private keys. |
| `providerOrUrl`     | `string\|object` | `null` | [x] | URI or Ethereum client to send all other non-transaction-related Web3 requests |
| `nodeAddress`       | `string` | `null` | [ ] | Node Address. |
| `expiration `       | `number` | `null` | [ ] | Expiration. |
| `addressIndex`      | `number` | `0` | [ ] | If specified, will tell the provider to manage the address at the index specified |
| `numberOfAddresses` | `number` | `1` | [ ] | If specified, will create `numberOfAddresses` addresses when instantiated |
| `shareNonce`        | `boolean` | `true` | [ ] | If `false`, a new WalletProvider will track its own nonce-state |
| `derivationPath`    | `string` | `"m/44'/60'/0'/0/"` | [ ] | If specified, will tell the wallet engine what derivation path should use to derive addresses. |
| `pollingInterval`   | `number` | `4000` | [ ] | If specified, will tell the wallet engine to use a custom interval when polling to track blocks. Specified in milliseconds. |
| `chainId`           | `number\|string` | `undefined` | [ ] | Specify to enable signed transactions that are EIP-155 compliant for major chains. |


To include in your truffle-config.js

```javascript
networks: {
    network_name: {
        provider: () => new GasModelProvider( PRIVATE_KEY, NODE_RPC, NODE_ADDRESS, EXPIRATION ),
        network_id: "*",
        gas: 115500000,
        gasPrice: 0,
        from: ADDRESS
    }
}
```

Where:
    - PRIVATE_KEY: is the Private Key of the ADDRESS
    - ADDRESS: is the Ethereum address of the tx sender
    - NODE_ADDRESS: is the Node Address in the Gas Model
    - EXPIRATION: is the expiration time in the Gas Model
    - RPC: is the RPC url of the writer node

Some other examples can be found below:

```javascript
const HDWalletProvider = require("@lacchain/truffle-gas-model-provider");
const Web3 = require("web3");
const mnemonicPhrase = "mountains supernatural bird..."; // 12 word mnemonic
let provider = new GasModelProvider({
  mnemonic: {
    phrase: mnemonicPhrase
  },
  providerOrUrl: "http://localhost:8545",
  nodeAddress: '0xd00e6624a73f88b39f82ab34e8bf2b4d226fd768',
  expiration: 1736394529
});

// Or, alternatively pass in a zero-based address index.
provider = new GasModelProvider({
  mnemonic: mnemonicPhrase,
  providerOrUrl: "http://localhost:8545",
  addressIndex: 5,
  nodeAddress: '0xd00e6624a73f88b39f82ab34e8bf2b4d226fd768',
  expiration: 1736394529
});

// Or, use your own hierarchical derivation path
provider = new GasModelProvider({
  mnemonic: mnemonicPhrase,
  providerOrUrl: "http://localhost:8545",
  numberOfAddresses: 1,
  shareNonce: true,
  derivationPath: "m/44'/137'/0'/0/",
  nodeAddress: '0xd00e6624a73f88b39f82ab34e8bf2b4d226fd768',
  expiration: 1736394529
});

// To make HDWallet less "chatty" over JSON-RPC,
// configure a higher value for the polling interval.
provider = new GasModelProvider({
  mnemonic: {
    phrase: mnemonicPhrase
  },
  providerOrUrl: "http://localhost:8545",
  pollingInterval: 8000,
  nodeAddress: '0xd00e6624a73f88b39f82ab34e8bf2b4d226fd768',
  expiration: 1736394529
});

// HDWalletProvider is compatible with Web3. Use it at Web3 constructor, just like any other Web3 Provider
const web3 = new Web3(provider);

// Or, if web3 is alreay initialized, you can call the 'setProvider' on web3, web3.eth, web3.shh and/or web3.bzz
web3.setProvider(provider)

// ...
// Write your code here.
// ...

// At termination, `provider.engine.stop()' should be called to finish the process elegantly.
provider.engine.stop();
```

**Note: If both mnemonic and private keys are provided, the mnemonic is used.**

## Copyright 2022 LACChain

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

---
_Source: https://npm.io/package/@lacchain/truffle-gas-model-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
