ledgermasterjs v1.0.16
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 ledgermasterjsHow 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.
| Parameter | Type | Description |
|---|---|---|
| rpc_url | string | rpc 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
| Key | Value Type | Description |
|---|---|---|
| address | string | address of created wallet |
| encryptedPk | string | The value that encrypts the password and secret key of the generated wallet |
| decryptedPk | string (Optional) | The value that private key |
const wallet = {
address: "",
encryptedPk: "",
decryptedPk: "",
};- generate Function to generate Wallet
| Parameter | Type | Description |
|---|---|---|
| password | string | Password to use when using the wallet's private key |
| @return | WalletType | Nonce value of the corresponding address |
| @throw | error | password is required |
//example
const wallet = ledgermasterjs.Wallet.generate("1234");- changePassword Change password to access wallet
| Parameter | Type | Description |
|---|---|---|
| oldPassword | string | Existing password |
| newPassword | string | New password |
| wallet | WalletType | Wallet to change |
| @return | WalletType | Password-altered wallet to access |
| @throw | error | New 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
| Parameter | Type | Description |
|---|---|---|
| wallet | WalletType | User's Wallet |
| password | string | password |
| @return | string | private key |
| @throw | error | Invalid 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
| Parameter | Type | Description |
|---|---|---|
| web3 | Web3 | Web3 Instance |
| contractAddress | string | Contract address |
| contractABI | Array | Contract ABI |
| method | string | Name of the method to request contact call |
| params | Array | Parameter of the method to request contact call |
| @return | Promise<any> | Result value for contract call request |
| @throw | error | Error 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
| Parameter | Type | Description |
|---|---|---|
| transactionConfig | TransactionConfig | Options to create a transaction to run a contract |
| txCommonOption | CommonOption | Value returned by getTransactionCommonOption() |
| gasPrice | string (optional) | Custom gas price |
| gasLimit | string (optional) | custom gas limit |
| @return | Transaction | Create Contract Execution Transactions |
| @throw | error | Error 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
| Parameter | Type | Description |
|---|---|---|
| transaction | Transaction | Contract execution transactions created using makeContractExecutionTransaction() |
| wallet | WalletType | User's wallet |
| password | string | wallet password |
| @return | string | signed raw transaction |
| @throw | error | Error 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
| Parameter | Type | Description |
|---|---|---|
| transaction | Transaction | Contract execution transactions created using makeContractExecutionTransaction() |
| privateKey | string | wallet private key |
| @return | string | signed raw transaction |
| @throw | error | Error for signed transaction |
//example
const wallet = ledgermasterjs.Wallet.generate("1234");
const signedTx = ledgermasterjs.Transaction.signTransactionWithPrivateKey(tx, "0x689af8efa8c651a91ad287602527f3af2fe9f6501a7ac4b061667b5a93e037fd");- sendTransaction
Send signed transactions to blockchain
| Parameter | Type | Description |
|---|---|---|
| web3 | Web3 | web3 instance |
| rawTransaction | string | signed raw transaction |
| @return | Promise<TransactionReceipt> | Receipt that comes out after it is registered in the block |
| @throw | error | Error 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
| Parameter | Type | Description |
|---|---|---|
| gasPrice | string(optional) | gas price you want to convert to hex |
| @return | string | Converted 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
| Parameter | Type | Description |
|---|---|---|
| gasLimit | string(optional) | gas limit you want to convert to hex |
| @return | string | Converted 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
| Parameter | Type | Description |
|---|---|---|
| customChainId | string(optional) | gas limit you want to convert to hex |
| @return | CommonOption | Default Options for Creating Transactions |
//example
const txOption = ledgermasterjs.TransactionUtils.getTransactionCommonOption();
const customTxOption = ledgermasterjs.TransactionUtils.getTransactionCommonOption("1317");