1.0.16 • Published 9 days ago

ledgermasterjs v1.0.16

Weekly downloads
-
License
MIT
Repository
-
Last release
9 days ago

LedgerMaster JS SDK

Get Started

Use Browser

JsDelivr

<script src="https://cdn.jsdelivr.net/npm/ledgermasterjs@1.0.15/dist/index.min.js"></script>

Unpkg

<script src="https://unpkg.com/ledgermasterjs@1.0.15/dist/index.min.js"></script>

Use Npm

npm install ledgermasterjs

How to Use

In Browser

<script>
  const web3 = new ledgermasterjs.Web3Client("");
</script>

In Node

import ledgermasterjs from "ledgermasterjs";
// or
import { Contract, Wallet, Web3Client, ... } from "ledgermasterjs";

API

Web3Client

The Web3Client class creates a Web3 instance for interacting with Ethereum-based networks.

ParameterTypeDescription
rpc_urlstringrpc node to connect to web3
// example
const web3 = new ledgermasterjs.Web3Client("http://localhost:8545");

getNonce Retrieves the current nonce value for the specified wallet address. |Parameter|Type|Description| |:---:|:---:|:---| |walletAddress|string|Wallet address| |@return | Promise<number> | Nonce value of the corresponding address |

//example
const web3 = new ledgermasterjs.Web3Client("http://localhost:8545");

await web3.getNonce(walletAddress);

getWeb3 Returns the created Web3 instance. |Parameter|Type|Description| |:---:|:---:|:---| |@return | Web3 | Web3 Instances |

//example
const web3 = new ledgermasterjs.Web3Client("http://localhost:8545");

web3.getWeb3();

Wallet

Module for creating and managing Wallet

- WalletType components of wallet type objects

KeyValue TypeDescription
addressstringaddress of created wallet
encryptedPkstringThe value that encrypts the password and secret key of the generated wallet
decryptedPkstring (Optional)The value that private key
const wallet = {
  address: "",
  encryptedPk: "",
  decryptedPk: "",
};

- generate Function to generate Wallet

ParameterTypeDescription
passwordstringPassword to use when using the wallet's private key
@returnWalletTypeNonce value of the corresponding address
@throwerrorpassword is required
//example
const wallet = ledgermasterjs.Wallet.generate("1234");

- changePassword Change password to access wallet

ParameterTypeDescription
oldPasswordstringExisting password
newPasswordstringNew password
walletWalletTypeWallet to change
@returnWalletTypePassword-altered wallet to access
@throwerrorNew password is same as old password
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const newWallet = ledgermasterjs.Wallet.changePassword("1234", "12345", wallet);

- decryptPrivateKey Return privatekey using password and encrypted value

ParameterTypeDescription
walletWalletTypeUser's Wallet
passwordstringpassword
@returnstringprivate key
@throwerrorInvalid password
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const privateKey = ledgermasterjs.Wallet.decryptPrivateKey(wallet, "1234");

Contract

Module for Call Contract State

- call Return the result value for the contract call method

ParameterTypeDescription
web3Web3Web3 Instance
contractAddressstringContract address
contractABIArrayContract ABI
methodstringName of the method to request contact call
paramsArrayParameter of the method to request contact call
@returnPromise<any>Result value for contract call request
@throwerrorError for contract call request
//example
async function contractCall() {
  const web3 = new ledgermasterjs.Client("http://localhost:8545");
  const result = await ledgermasterjs.Contract.call(web3.getWeb3, "0x...", [...abi], "getText", []);
  console.log("Contract Call: ", result);
  return result;
}

Transaction

Module for generating and signing transactions

TransactionConfig Options to create a transaction to run a contract | Key | Value Type | Description | | :---------: | :---------------: | :---------------------------------------------------------------------------- | | contractAddress | string | Contract to execute the function | | accountAddress | string | User's wallet address | | abi | Array | Contract ABI | | nonce | number | Nonce value of the user's wallet address | | method | string | Name of the method to request contact execute | | params | Array | The value assigned to the array of parameters of the contract function in order |

const transactionConfig = {
  contractAddress: "",
  accountAddress: "",
  abi: [
    ...
     {
        inputs: [
          {
            internalType: "address",
            name: "to",
            type: "address",
          },
          {
            internalType: "uint256",
            name: "value",
            type: "uint256",
          },
        ],
        name: "transfer",
        outputs: [
          {
            internalType: "bool",
            name: "",
            type: "bool",
          },
        ],
        stateMutability: "nonpayable",
        type: "function",
      };
      ...
  ],
  nonce: 0,
  method: "",
  params: [""],
};

- makeContractExecutionTransaction Create a transaction to execute a function in a contract

ParameterTypeDescription
transactionConfigTransactionConfigOptions to create a transaction to run a contract
txCommonOptionCommonOptionValue returned by getTransactionCommonOption()
gasPricestring (optional)Custom gas price
gasLimitstring (optional)custom gas limit
@returnTransactionCreate Contract Execution Transactions
@throwerrorError for create contract execution transaction
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const txConfig = {
	contractAddress: "0x ...",
	accountAddress: wallet.address,
	abi: [ ... ],
	nonce: 0,
	method: "setText",
	params: ["text"],
};
const txOption = ledgermasterjs.TransactionUtils.getTransactionCommonOption();
const tx = ledgermasterjs.Transaction.makeContractExecuteTransaction(txConfig, txOption);

- signTransactionWithWallet Sign the transaction created with your own wallet

ParameterTypeDescription
transactionTransactionContract execution transactions created using makeContractExecutionTransaction()
walletWalletTypeUser's wallet
passwordstringwallet password
@returnstringsigned raw transaction
@throwerrorError for signed transaction
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const signedTx = ledgermasterjs.Transaction.signTransactionWithWallet(tx, wallet, "1234");

- signTransactionWithPrivateKey Sign the transaction created with your own private key

ParameterTypeDescription
transactionTransactionContract execution transactions created using makeContractExecutionTransaction()
privateKeystringwallet private key
@returnstringsigned raw transaction
@throwerrorError for signed transaction
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const signedTx = ledgermasterjs.Transaction.signTransactionWithPrivateKey(tx, "0x689af8efa8c651a91ad287602527f3af2fe9f6501a7ac4b061667b5a93e037fd");

- sendTransaction

Send signed transactions to blockchain

ParameterTypeDescription
web3Web3web3 instance
rawTransactionstringsigned raw transaction
@returnPromise<TransactionReceipt>Receipt that comes out after it is registered in the block
@throwerrorError while transmitting to blockchain
//example
const web3 = new ledgermasterjs.Web3Client("http://localhost:8545");

const wallet = ledgermasterjs.Wallet.generate("1234");
const signedTx = ledgermasterjs.Transaction.signTransaction(tx, wallet, "1234");
const receipt = await sendTransaction(web3.getWeb3(), signedTx);

Transaction Utils

Utils to create transactions

- getGasPriceHex Convert gas price to hex or return the default gas price

ParameterTypeDescription
gasPricestring(optional)gas price you want to convert to hex
@returnstringConverted hex value with parameters, default gas price without parameters
//example
const gasPrice = ledgermasterjs.TransactionUtils.gasPriceHex();
const customGasPrice = ledgermasterjs.TransactionUtils.gasPriceHex("300000");

- getGasLimitHex Convert gas limit to hex or return the default gas limit

ParameterTypeDescription
gasLimitstring(optional)gas limit you want to convert to hex
@returnstringConverted hex value with parameters, default gas limit without parameters
//example
const gasLimit = ledgermasterjs.TransactionUtils.getGasLimitHex();
const customGasLimit = ledgermasterjs.TransactionUtils.getGasLimitHex("300000");

- getTransactionCommonOption Convert gas limit to hex or return the default gas limit

ParameterTypeDescription
customChainIdstring(optional)gas limit you want to convert to hex
@returnCommonOptionDefault Options for Creating Transactions
//example
const txOption = ledgermasterjs.TransactionUtils.getTransactionCommonOption();
const customTxOption = ledgermasterjs.TransactionUtils.getTransactionCommonOption("1317");
1.0.16

9 days ago

1.0.15

23 days ago

1.0.14

23 days ago

1.0.13

23 days ago

1.0.11

23 days ago

1.0.10

23 days ago

1.0.12

23 days ago

1.0.9

25 days ago

1.0.8

27 days ago

1.0.7

27 days ago

1.0.6

27 days ago

1.0.4

27 days ago

1.0.2

27 days ago

1.0.3

27 days ago

1.0.1

29 days ago

1.0.0

29 days ago