Charged Particles
  • What is Charged Particles
  • GETTING STARTED
    • Quick Start
  • CHARGED PARTICLES PROTOCOL
    • Protocol Overview
      • How It Works
      • Current Status
      • Protocol Revenue
      • Protocol Features
    • Why Use Charged Particles?
      • NFT Platforms And How They Differ
      • Charged Particles NFTs - What Are They?
    • How to Use Charged Particles
      • Minting an NFT
      • Energizing an NFT
      • Manage an NFT
      • Using A Test Network
      • Migrating Particles from V1 to V2
    • Developer Docs
      • System Overview
      • Quickstart
        • Read and Write to Contracts
        • Read from the Subgraph
        • Get Kovan ETH + ERC20s
        • VSCode Node.js Typescript Debugging
      • Smart Contracts
        • V2
          • Charged Particles Contract (V2)
          • Charged Settings Contract (V2)
          • Charged State Contract (V2)
          • ProtonB Contract
        • V1
          • Charged Particles Contract
          • Charged Settings Contract
          • Charged State Contract
          • Proton Contract
        • Error Codes
      • Protocol Subgraph
    • IONX
      • IONX Token Addresses
      • IONX Rewards
    • Web3 Packs
    • Liquidity Mining
      • Base Reward Program
      • Leptons
    • Protocol Governance
      • Governance Process
      • Creating a Proposal
      • Voting
      • Delegating Votes
    • Projects + Use Cases
    • Allowlist Application
    • Team
    • Guilds
    • Roadmap
    • Hackathons
      • Hackathon Ideas
      • Previous Hackathons
    • Dune Analytics
  • SDK
    • Charged Particles SDK Overview
    • Quick Start
    • API
    • Advanced Use
    • Types
    • Common Issues / FAQ
    • Common Terminology
  • RESOURCES
    • Hiring!
      • Full-stack/Back-end Web3 Engineer
      • Create Your Own Position
    • Glossary of Terms
    • FAQs
      • Protocol and app.charged.fi
      • Governance
      • Other
      • How to report a bug
    • External Contracts Allowlisted
    • Audits
    • Legal
      • Beta End User License Agreement (EULA)
      • Privacy Policy
      • Policies & Terms of Service
    • Media Kit
  • Additional Resources
    • Discord
    • Telegram
    • Twitter
    • Medium
    • Github
    • LinkedIn
    • Instagram
    • TikTok
Powered by GitBook
On this page
  • Installation
  • Getting started
  • Configuration
  • Interacting with the protocol
  • Utilities

Was this helpful?

  1. SDK

Quick Start

Installation

The SDK is available as a NPM package. Install using

yarn add @charged-particles/sdk

npm install @charged-particles/sdk

Getting started

// Node
import Charged from '@charged-particles/sdk'

// Creating a signer. This is optional, used for making transactions.
const wallet = ethers.wallet.fromMnemonic(seedPhrase);

// Multiple providers array
const mySpecialProviders = [
	{
		network: 1,
		service: { 
			'alchemy': 'apiKey',
		},
	},
	{
		network: 42,
		service: {
			'rpcUrl': '<https://eth-kovan.alchemyapi.io/v2/><key>'
		}
	}
];
const charged = new Charged({providers: mySpecialProviders, signer: wallet});

// Ethers
const ethersProvider = ethers.getDefaultProvider();
const charged = new Charged({providers: ethersProvider, signer: wallet});

// Web3
var web3 = new Web3('<http://localhost:8545>');
const charged = new Charged({providers: ethersProvider, signer: wallet});
// Web
import Charged from '@charged-particles/sdk'

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

Be careful not to keep your secrets, or private key in clear text !

Configuration

Charged class object constructor config parameter.

{
	sdk: { 
		// checks that signer network matches respective contract
		NftBridgeCheck: false 
	},
	transactionOverride: { 
		from: ''
		value: '' 
		gasPrice: '' 
		gasLimit: ''
		blockTag: ''
		nonce:  ''
	}
}

Interacting with the protocol

When reading and/or writing you will need to define which NFT you are working with.

/*
Before you call any functions on a specific particle, you'll need to specify 
which one you are going to work with.
*/

const contractAddress = '0x1234';
const tokenId = 33;

const nft = charged.NFT(contractAddress, tokenId);

// This energizes our nft with 47 DAI tokens.
const txReciept = await nft.energize(
    'aave.B',
    '0xDAI',
    ethers.utils.parseEther('47')
);

// Get the energized mass
const massBN = await nft.getMass('aave.B', '0xDAI');

// Discharges all of the interest accrued by the DAI tokens to my wallet.
const txReceipt2 = await nft.discharge('0xMYADDRESS', 'aave.B', '0xDAI');

Utilities

The SDK provides a set of utility functions. The example below shows the format that all the functions are called by.

// This will fetch the addresses of a contract associated with the main contract
const stateAddress = await charged.utils.getStateAddress()
PreviousCharged Particles SDK OverviewNextAPI

Last updated 2 years ago

Was this helpful?