scrt-evm-js
v1.0.0
Published
The **SecretEvmJS** library provides a simple interface for interacting with an Ethereum-compatible blockchain using Secret Network functionalities. It includes methods for encrypting and decrypting data, as well as requesting funds from a faucet.
Readme
SecretEvmJS Library
The SecretEvmJS library provides a simple interface for interacting with an Ethereum-compatible blockchain using Secret Network functionalities. It includes methods for encrypting and decrypting data, as well as requesting funds from a faucet.
Features
- RPC Integration: Interact with an EVM-compatible blockchain via RPC.
- Encryption and Decryption: Leverage SCRT encryption and decryption mechanisms.
- Faucet Interaction: Request funds from a faucet to test accounts.
Installation
To install the library, run:
npm install scrt-evm-jsAPI Reference
constructor(rpcUrl?: string, faucetUrl?: string)
Creates a new instance of SecretEvmJS.
rpcUrl: The RPC URL of the blockchain node (default:http://localhost:8545).faucetUrl: The URL of the faucet service (default:http://localhost:8080).
getFunds(address: string, url?: string): Promise<void>
Requests funds for a specified address from the faucet.
address: The address to receive the funds.url: Optional custom faucet URL (default: instance'sfaucetUrl).
encrypt(data: string | number): Promise<string>
Encrypts the provided data using SCRT encryption.
data: The data to encrypt (either a string or number).- Returns: A promise resolving to the encrypted data.
decrypt(data: string): Promise<string>
Decrypts the provided encrypted data.
data: The encrypted data to decrypt (hexadecimal string).- Returns: A promise resolving to the decrypted data.
Example Usage
Below is an example of how to use the library:
import { ScrtEvmClient } from 'scrt-evm-client';
async function main() {
// Initialize the client
const client = new ScrtEvmClient('http://localhost:8545', 'http://localhost:8080');
// Request funds from the faucet
const address = '0xYourEthereumAddressHere';
console.log(`Requesting funds for ${address}...`);
await client.getFunds(address);
console.log('Funds received.');
// Encrypt some data
const dataToEncrypt = 12345;
const encryptedData = await client.encrypt(dataToEncrypt);
console.log('Encrypted Data:', encryptedData);
// Decrypt the data
const decryptedData = await client.decrypt(encryptedData);
console.log('Decrypted Data:', decryptedData);
}
// Run the example
main().catch((error) => {
console.error('Error:', error);
});Requirements
- Node.js: v14 or later.
- TypeScript: v4 or later (if using TypeScript).
Development
Clone the repository:
git clone https://github.com/scrtlabs/scrt-evm-js.git
cd scrt-evm-jsInstall dependencies:
npm installRun tests:
npm testLibrary Developer
Install Dependencies
To install the dependencies, run:
pnpm installBuild
To build the library, run:
pnpm buildIt will build the library in the dist directory.
Test
To run tests, use:
pnpm testLicense
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature/fix.
- Submit a pull request.
For major changes, please open an issue first to discuss what you would like to change.
If you have any questions or issues, feel free to open an issue on GitHub.
