# API

## Charged

#### Parameters

* `params` **ChargedConstructor** Charged parameter object.

### Examples

```javascript
const charged = new Charged({providers: window.ethereum});
const allStateAddresses = await charged.utils.getStateAddress();

const polygonProvider = [
 { 
   network: 137, 
   service: {alchemy: process.env.ALCHEMY_POLYGON_KEY}
 }
];
const charged = new Charged({providers: polygonProvider})
```

#### ChargedConstructor

Charged class constructor object parameter.

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

**Properties**

* `providers` **(**[**Array**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)**\<NetworkProvider> | providers.Provider | providers.ExternalProvider)?** Provider for connection to the Ethereum network.
* `signer` **Signer?** Needed to send signed transactions to the Ethereum Network to execute state changing operations.
* `config` **ConfigurationParameters**

## Utilities

### Examples

```javascript
const charged = new Charged({providers: window.ethereum});
const creatorAnnuities = await charged.utils.getStateAddress();
```

Returns **UtilsService**

### getStateAddress

Get the address of the chargedState contract.

Returns [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) state contract address

### getSettingsAddress

Get the address of the chargedSettings contract.

Returns [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) settings contract address

### getManagersAddress

Get the address of the chargedManagers contract.

Returns [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) manager contract address

### getFeesForDeposit

Get the deposit fee of the protocol.

Returns [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) protocol fee amount.

##

## NFT

#### Parameters

* `contractAddress` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
* `tokenId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)

### Examples

```javascript
const charged = new Charged({providers: window.ethereum});

const nft = charged.NFT( '0xd1bce91a13089b1f3178487ab8d0d2ae191c1963', 43);

const creatorAnnuities = await nft.getCreatorAnnuities();
```

Returns **NftService** Instance of the NFT connected to the charged particle protocol

### getMass

Gets the amount of asset tokens that have been deposited into the Particle.

**Parameters**

* `walletManagerId` **WalletManagerId** The ID of the wallet manager to check.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token to check.

Returns **BigNumber** The Amount of underlying assets held within the token.

### getCharge

Gets the amount of interest that the particle has generated.

**Parameters**

* `walletManagerId` **WalletManagerId** The ID of the Wallet Manager.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset Token to check.

Returns **BigNumber** The amount of interest generated.

### getKinectics

Gets the amount of LP Tokens that the Particle has generated.

**Parameters**

* `walletManagerId` **WalletManagerId** The ID of the Wallet Manager.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The Address of the Asset Token to check.

Returns **BigNumber** The amount of LP tokens that have been generated.

### getBonds

Gets the total amount of ERC721 tokens that the Particle holds.

**Parameters**

* `basketManagerId` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The ID of the BasketManager to check.

Returns **BigNumber** The total amount of ERC721 tokens that are held within the Particle.

### getCreatorAnnuities

Gets the amount of creator annuities reserved for the creator for the specified NFT.

Returns **address** The address of the creator.

Returns [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The percentage amount of annuities reserved for the creator.

### getCreatorAnnuitiesRedirect

Get the address that receives creator annuities for a given Particle/ Defaults to creator address if it has not been redirected.

Returns **address** The address of the creator.

Returns [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The percentage amount of annuities reserved for the creator.

### tokenURI

Gets the tokenUri using the tokenId and contractAddress of the Particle.

Returns [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) Token metadata URI.

### getDischargeState

Gets the Discharge timelock state of the Particle.

**Parameters**

* `sender` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address approved for Discharging assets from the Particle.

Returns **\[**[**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**,** [**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**, BigNumber, BigNumber]** \[allowFromAll, isApproved, timelock, empLockExpiry]

### getReleaseState

Gets the Discharge timelock state of the Particle.

**Parameters**

* `sender` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address approved for Releasing assets from the Particle.

Returns **\[**[**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**,** [**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**, BigNumber, BigNumber]** \[allowFromAll, isApproved, timelock, empLockExpiry]

### getBondsState

Gets the Bonds Timelock state of the Particle.

**Parameters**

* `sender` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address approved for removing Bond assets from the Particle.

Returns [**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) allowFromAll

Returns [**boolean**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) isApproved

Returns **BigNumber** timelock

Returns **BigNumber** tempLockExpiry

### energize

Fund particle with asset token Must be called by the account providing the asset. Account must also approve THIS contract as operator as asset.

If you are getting gas limit errors this may be because you forgot to approve the contract as operator of asset

**Parameters**

* `walletManagerId` **WalletManagerId** The Asset-Pair to Energize the Token with
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The Address of the Asset Token being used
* `assetAmount` **BigNumberish** The Amount of Asset Token to Energize the Token with
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to
* `referrer` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**?**

**Examples**

```javascript
// Asset amount expects a big numberish type. If you do not supply a
// big number object, ethers will assume you are working in wei.
// Deposits 20 USDC tokens into our particle that will accrue interest.

const USDCoinAddress = '0xUSDC';
const result = await nft.energize(
  'aave.B',
  USDCoinAddress,
  ethers.utils.parseUnits("20", 6),
);
// Or, deposit assets that will not accrue interest
// or assets that are not supported by our yield generating protocols (e.g. aave)

// For example, we will energize our particle with 20 monkey coins
// This will not generate interest.
const monkeyCoinAddress = '0xMONKEY';
const result = await nft.energize(
  'generic.B',
  monkeyCoinAddress,
  ethers.utils.parseUnits("20")
);
```

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L267)

### discharge

Allows the owner or operator of the token to collect or transfer the interest generated from the token without removing the underlying asset that is held within the token.

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the discharged asset tokens.
* `walletManagerId` **WalletManagerId** The wallet manager of that assets to discharge from the token.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token being discharged.
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.j

**Examples**

```javascript
const myWallet = '0xWALLET';
const rocketPoolAddress = '0xRPL';
const result = await nft.discharge(
  myWallet,
  'aave.B',
  rocketPoolAddress,
);

// You can also discharge to any arbitrary wallet!
// Let's send all of our interest accrued by our DAI to Vitalik.
const vitaliksWallet = '0xCOOLGUY';
const daiAddress = '0xDAI';
const result = await nft.discharge(
  vitaliksWallet,
  'aave.B',
  daiAddress,
)
```

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L310)

### dischargeAmount

Allows the owner or operator of the Token to collect or transfer a specific amount of the interest generated from the token without removing the underlying Asset that is held within the token.

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the discharged asset tokens.
* `walletManagerId` **WalletManagerId** The wallet manager of the assets to discharge from the token.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token being discharged.
* `assetAmount` **BigNumberish** The specific amount of asset token to discharge from the particle.
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L351)

### dischargeForCreator

Allows the Creator of the Token to collect or transfer a their portion of the interest (if any) generated from the token without removing the underlying Asset that is held within the token.

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the discharged asset tokens
* `walletManagerId` **WalletManagerId** The wallet manager of the assets to discharge from the token
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token being discharged
* `assetAmount` **BigNumberish** The specific amount of asset token to discharge from the particle
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L393)

### release

Releases the full amount of asset + interest held within the particle by LP of the assets. To release NFT assets from your particle, see [break bond](https://docs.charged.fi/sdk/broken-reference).

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the released asset tokens.
* `walletManagerId` **WalletManagerId** The wallet manager of the assets to release from the token.
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token being released.
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

**Examples**

```javascript
// Release the DAI from our particle. Withdraws the interest (if any) as well!
const receiver = '0xMYWALLET';
const daiAddress = '0xDAI';
const result = nft.release(
  receiver,
  'aave.B',
  daiAddress,
);
```

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L440)

### releaseAmount

Releases a partial amount of asset + interest held within the particle by LP of the assets.

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the released asset tokens
* `walletManagerId` **WalletManagerId** The wallet manager of the assets to release from the token
* `assetToken` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the asset token being released
* `assetAmount` **BigNumberish** The specific amount of asset token to release from the particle
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L483)

### bond

Deposit other NFT assets into the particle. Must be called by the account providing the asset. Account must approve THIS contract as operator of asset.

**Parameters**

* `basketManagerId` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The basket to deposit the NFT into.
* `nftTokenAddress` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the NFT token being deposited.
* `nftTokenId` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The ID of the NFT token being deposited.
* `nftTokenAmount` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The amount of tokens to deposit (ERC1155-specific).
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

**Examples**

```javascript
const nftTokenAddress = '0xMOONBIRDS';
const tokenId = '12';
const result = await nft.bond(
  'generic.B',
  nftTokenAddress,
  tokenId,
  1,
);

// We have 12 erc-1155 nfts that we want to bond to the particle.
const nftTokenAddress = '0xCOOLGAME';
const tokenId = '78';
const result = await nft.bond(
  'generic.B',
  nftTokenAddress,
  tokenId,
  12
);
```

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L533)

### breakBond

Release NFT assets from the particle.

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address to receive the released asset tokens.
* `basketManagerId` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The basket to release the NFT from.
* `nftTokenAddress` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The address of the NFT token being released.
* `nftTokenId` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The ID of the NFT token being released.
* `nftTokenAmount` [**Number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The amount of tokens to deposit (ERC1155-specific).
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

**Examples**

```javascript
// We bonded 14 erc-1155 nfts to our particle. We want to release 3.
// When working with erc-721 use 1 for nftTokenAmount.
const receiver = '0xMYWALLET';
const nftTokenAddress = '0xNFTS';
const tokenId = '35';
const result = await nft.breakBond(
  receiver,
  'generic.B',
  nftTokenAddress,
  tokenId,
  3
);
```

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedParticles.sol#L570)

### releaseTimelock

Sets a timelock on the ability to release the assets of a particle.

**Parameters**

* `unlockBlock` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The Ethereum block number to timelock until (\~15 seconds per block).
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedState.sol#L440)

### dischargeTimelock

Sets a timelock on the ability to discharge the assets of a particle

**Parameters**

* `unlockBlock` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The Ethereum block number to timelock until (\~15 seconds per block).
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedState.sol#L406)

### bondsTimelock

Sets a timelock on the ability to break the covalent bond of a particle

**Parameters**

* `unlockBlock` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) The Ethereum block number to timelock until (\~15 seconds per block).
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedState.sol#L474)

### setCreatorAnnuities

Sets the custom configuration for creators of proton-based NFTs Must be called by account that created and owns the particle

**Parameters**

* `creator` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The creator's address of the proton-based NFT.
* `annuityPercent` **BigNumberish** The percentage of interest-annuities to reserve for the creator. In decimal this can range from 0 - 10000. 5712 would be 57.12%..
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedSettings.sol#L200)

### setCreatorAnnuitiesRedirect

Sets a custom receiver address for the creator annuities Must be called by account that created and owns the particle

**Parameters**

* `receiver` [**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The receiver of the creator interest annuities.
* `chainId` [**number**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**?** Optional parameter that allows for the user to specify which network to write to.

Returns [**Promise**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**\<ContractTransaction>** - Details from the transaction.

[Solidity Contract Method](https://github.com/Charged-Particles/charged-particles-universe/blob/a2c54a8b125e416ff600b731d2d13576223bfac7/contracts/ChargedSettings.sol#L218)
