@polymarket/abstract-signer
v0.0.8
Published
Abstraction over the ethers v5 Wallet, ethers v5 JsonRpcSigner or Viem WalletClient
Maintainers
Keywords
Readme
abstract-signer
Abstraction over the ethers v5 Wallet, ethers v5 JsonRpcSigner or Viem WalletClient
Installation
pnpm install @polymarket/abstract-signerUsage
import { ethers } from "ethers";
import { createWalletClient, http} from "viem";
import { privateKeyToAccount } from 'viem/accounts';
import { createAbstractSigner, IAbstractSigner, Transaction } from "@polymarket/abstract-signer";
const chainId = parseInt(`${process.env.CHAIN_ID}`);
// ethers
// Instantiate an ethers Wallet
const provider = new ethers.providers.JsonRpcProvider(`${process.env.RPC_URL}`);
const pk = new ethers.Wallet(`${process.env.PK}`);
const wallet = pk.connect(provider);
// viem
// Instantiate a Viem wallet
const account = privateKeyToAccount(`${process.env.PK}`);
const wallet = createWalletClient({
account: account,
transport: http(`${process.env.RPC_URL}`)
});
const abstractSigner: IAbstractSigner = createAbstractSigner(chainId, wallet);
const tx : Transaction = {
to: await abstractSigner.getAddress(),
value: 10000000000000000n,
gasPrice: 100000000000n,
};
const txHash = await abstractSigner.sendTransaction(tx);
console.log(`Tx hash: ${txHash}`);
const receipt = await abstractSigner.waitTillMined(txHash);
console.log(receipt);