@ethersproject/providers#JsonRpcSigner TypeScript Examples
The following examples show how to use
@ethersproject/providers#JsonRpcSigner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: contractApi.ts From commonwealth with GNU General Public License v3.0 | 6 votes |
export async function attachSigner<CT extends Contract>(
wallets: WebWalletController,
sender: Account<any>,
contract: CT
): Promise<CT> {
const signingWallet = await wallets.locateWallet(sender, ChainBase.Ethereum);
let signer: JsonRpcSigner;
if (signingWallet instanceof MetamaskWebWalletController
|| signingWallet instanceof WalletConnectWebWalletController) {
const walletProvider = new ethers.providers.Web3Provider(signingWallet.provider as any);
// 12s minute polling interval (default is 4s)
walletProvider.pollingInterval = 12000;
signer = walletProvider.getSigner(sender.address);
} else {
throw new Error('Unsupported wallet');
}
if (!signer) {
throw new Error('Could not get signer.');
}
const ct = contract.connect(signer) as CT;
await ct.deployed();
return ct;
}
Example #2
Source File: ethers.ts From react-celo with MIT License | 6 votes |
useConnectedSigner = (): Maybe<JsonRpcSigner> => {
const getConnectedSigner = useGetConnectedSigner();
const [signer, setSigner] = useState<Maybe<JsonRpcSigner>>(null);
useEffect(() => {
let stale;
void (async () => {
const theSigner = await getConnectedSigner();
if (!stale) {
setSigner(theSigner);
}
setSigner(await getConnectedSigner());
})();
return () => {
stale = true;
};
}, [getConnectedSigner]);
return signer;
}
Example #3
Source File: ethers.ts From react-celo with MIT License | 6 votes |
useLazyConnectedSigner = (): {
signer: Maybe<JsonRpcSigner>;
address: Maybe<string>;
getConnectedSigner: () => Promise<JsonRpcSigner>;
} => {
const isMountedRef = useIsMounted();
const getConnectedSigner = useGetConnectedSigner();
const [signer, setSigner] = useState<Maybe<JsonRpcSigner>>(null);
const getConnectedSignerCb = useCallback(async () => {
const theSigner = await getConnectedSigner();
if (isMountedRef.current) {
setSigner(theSigner);
}
return theSigner;
}, [getConnectedSigner, setSigner, isMountedRef]);
return {
signer,
getConnectedSigner: getConnectedSignerCb,
address: signer?._address ?? null,
};
}
Example #4
Source File: ethers.ts From react-celo with MIT License | 6 votes |
useGetConnectedSigner = (): (() => Promise<JsonRpcSigner>) => {
const { kit, getConnectedKit, network } = useCelo();
const signer = useProviderOrSigner();
const { chainId, name } = network;
return useCallback(async () => {
if (kit.connection.defaultAccount) {
return signer as JsonRpcSigner;
}
const nextKit = await getConnectedKit();
const nextProvider = nextKit.connection.web3
.currentProvider as unknown as ExternalProvider;
return new Web3Provider(nextProvider, { chainId, name }).getSigner(
nextKit.connection.defaultAccount
);
}, [kit.connection.defaultAccount, getConnectedKit, signer, chainId, name]);
}
Example #5
Source File: ethers.ts From react-celo with MIT License | 6 votes |
useProviderOrSigner = (): Web3Provider | JsonRpcSigner => {
const { kit } = useCelo();
const provider = useProvider();
return useMemo(() => {
return kit.connection.defaultAccount
? provider.getSigner(kit.connection.defaultAccount)
: provider;
}, [provider, kit.connection.defaultAccount]);
}
Example #6
Source File: index.ts From panther-frontend-dex with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #7
Source File: index.ts From goose-frontend-amm with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #8
Source File: index.ts From goose-frontend-amm with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #9
Source File: index.ts From mozartfinance-swap-interface with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #10
Source File: index.ts From mozartfinance-swap-interface with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #11
Source File: index.ts From pancake-swap-exchange-testnet with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #12
Source File: index.ts From pancake-swap-exchange-testnet with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #13
Source File: index.ts From panther-frontend-dex with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #14
Source File: index.ts From limit-orders-lib with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(
library: Web3Provider,
account?: string
): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library;
}
Example #15
Source File: 0004-layer2-clearingHouse-amm-openPos.ts From perpetual-protocol with GNU General Public License v3.0 | 5 votes |
async function impersonateAccount(address: string): Promise<JsonRpcSigner> {
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [address],
})
return ethers.provider.getSigner(address)
}
Example #16
Source File: provider.test.ts From ccip-read with MIT License | 5 votes |
getSigner(addressOrIndex?: string | number): JsonRpcSigner {
return (this.parent as Web3Provider).getSigner(addressOrIndex);
}
Example #17
Source File: index.ts From forward.swaps with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #18
Source File: index.ts From forward.swaps with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #19
Source File: index.ts From sushiswap-exchange with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #20
Source File: index.ts From sushiswap-exchange with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #21
Source File: index.ts From luaswap-interface with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #22
Source File: index.ts From luaswap-interface with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #23
Source File: index.ts From vvs-ui with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #24
Source File: index.ts From vvs-ui with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #25
Source File: index.ts From pancakeswap-testnet with GNU General Public License v3.0 | 5 votes |
// account is not optional
export function getSigner(library: Web3Provider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked()
}
Example #26
Source File: index.ts From pancakeswap-testnet with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #27
Source File: bond.ts From wonderland-frontend with MIT License | 5 votes |
public getContractForBond(networkID: Networks, provider: StaticJsonRpcProvider | JsonRpcSigner) {
const bondAddress = this.getAddressForBond(networkID);
return new Contract(bondAddress, this.bondContractABI, provider);
}
Example #28
Source File: index.ts From cuiswap with GNU General Public License v3.0 | 5 votes |
// account is optional
export function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner {
return account ? getSigner(library, account) : library
}
Example #29
Source File: bond.ts From lobis-frontend with MIT License | 5 votes |
public getContractForBond(networkID: Networks, provider: StaticJsonRpcProvider | JsonRpcSigner) {
const bondAddress = this.getAddressForBond(networkID);
return new Contract(bondAddress, this.bondContractABI, provider);
}