@newki_pheasant/ethers-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@cloud-cryptographic-wallet/ethers-adapter

npm version

This package allows you to use Signer of ethers with a variety of cloud service key management systems.

Support Cloud Services

Install

$ npm install @cloud-cryptographic-wallet/ethers-adapter ethers

With Cloud Service

AWS KMS

$ npm install @cloud-cryptographic-wallet/aws-kms-signer
import { ethers } from "ethers";
import { AwsKmsSigner } from "@cloud-cryptographic-wallet/aws-kms-signer";
import { EthersAdapter } from "@cloud-cryptographic-wallet/ethers-adapter";

async function sendTxUsingAwsKmsSigner(rpcUrl: string) {
  const region = "us-east-1";
  const keyId = "e9005048-475f-4767-9f2d-0d1fb0c89caf";
  const awsKmsSigner = new AwsKmsSigner(keyId, { region });

  const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
  const signer = new EthersAdapter({ signer: awsKmsSigner }).connect(provider);

  const address = await signer.getAddress();
  console.log(address);
  console.log(ethers.utils.formatEther(await signer.getBalance()));

  const tx = await signer.sendTransaction({
    from: address,
    to: address,
  });

  console.log({ tx });

  const receipt = await tx.wait();

  console.log({ receipt });
}

Cloud Key Management

$ npm install @cloud-cryptographic-wallet/cloud-kms-signer
import { ethers } from "ethers";
import { CloudKmsSigner } from "@cloud-cryptographic-wallet/cloud-kms-signer";
import { EthersAdapter } from "@cloud-cryptographic-wallet/ethers-adapter";

async function sendTxUsingCloudKmsSigner(rpcUrl: string) {
  const name =
    "projects/aws-kms-provider/locations/asia-northeast1/keyRings/for-e2e-test/cryptoKeys/for-e2e-test/cryptoKeyVersions/1";
  const cloudKmsSigner = new CloudKmsSigner(name);

  const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
  const signer = new EthersAdapter({ signer: cloudKmsSigner }).connect(
    provider
  );

  const address = await signer.getAddress();
  console.log(address);
  console.log(ethers.utils.formatEther(await signer.getBalance()));

  const tx = await signer.sendTransaction({
    from: address,
    to: address,
  });

  console.log({ tx });

  const receipt = await tx.wait();

  console.log({ receipt });
}

Readme

Keywords

none

Package Sidebar

Install

npm i @newki_pheasant/ethers-adapter

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

32.7 kB

Total Files

9

Last publish

Collaborators

  • newki_pheasant