Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@ashetm/ng-ether
Advanced tools
Readme
@ashetm/ng-ether
is a library that simplify manipulation of library ethers
, and has a good interaction with Angular with its stream based with RXJS
. It provides also a test module that provide mock of window.ethereum
in a token (see below) for testing purpose.
You can install it with npm:
npm install @ashetm/ng-ether
You only need to import EtherModule
through forRoot
static method.
...
import { EtherModule } from '@ashetm/ng-ether';
...
@NgModule({
...
imports: [
...
EtherModule.forRoot(),
...
]
...
})
export class AppModule { }
@ashetm/ng-ether
exposes the following:
EtherModule
, that contains forRoot
static method to import in order to use the library with TEtherConfigurationRoot
optional configuration with abi and contract address of a deployed smart contractEtherTestModule
, that provide a mock of window.ethereum
through ETHER_TOKEN
(See below) for testing purposeTokens are InjectionToken<T>
that needs to be injected in order to get its value
ETHER_TOKEN
returns window.ethereum
object, if you wish a direct manipulationETHER_TOKEN_ABI
returns string abi
provided in configuration forRoot static methodETHER_TOKEN_ADDRESS_CONTRACT
returns addressContract
string provided in configuration forRoot static methodETHER_TOKEN_IS_METAMASK_WALLET
returns boolean, true if MetaMask wallet is installed in browserETHER_TOKEN_IS_WALLET_INSTALLED
returns boolean, true if the wallet is installed in browserETHER_TOKEN_NETWORK_ID
returns networkId
string provided in configuration forRoot static method, default value is any
EtherNetworkService
is a service concern all about network.
network$
is Observable<TEtherNetwork>
, it emits TEtherNetwork
value of network informationThose following are Observable
and emits when account or network change
blockNumber$
is Observable<number>
that emits a number
value of number of blockgasFee$
is Observable<TEtherBigNumber>
that emits a TEtherBigNumber
value, it concerns gas price of the current networkprice$
is Observable<number>
, it emits number
value of price of ETHAnd for methods, there is the following:
addNetwork(newNetwork: TEtherNetwork)
returns Observable<true | TEtherError>
listen to if a new network is created successfully and emits a value, of type either true
if success or TEtherNetworkChange = { newNetwork: TEtherNetwork; oldNetwork?: TEtherNetwork; }
for failure.
onNetworkChange()
returns Observable<TEtherNetworkChange>
listen to network change event and emits TEtherNetworkChange = { newNetwork: TEtherNetwork; oldNetwork?: TEtherNetwork; }
value that contains informations of new network and old network.
or the second definition
onNetworkChange(fn: (newNetwork: TEtherNetwork, oldNetwork?: TEtherNetwork) => void)
returns void
nothing, you need to provide a function with 2 arguments; first arguments is informùation of new network and second is information of old network.
switchNetwork(chainId: EEtherNetworkChainId)
returns Observable<true | TEtherError>
listen to if the switch to a specified network is done successfully and emits a value, of type either true
if success or TEtherNetworkChange = { newNetwork: TEtherNetwork; oldNetwork?: TEtherNetwork; }
for failure.
EtherTransactionService
is a service concern all about transaction.
For methods, there is the following:
prepareTransaction(addressWallet: string)
returns EtherTransactionRef
that contains 3 methods: sendEth(amount: number)
, sendGWei(amount: number)
and sendWei(amount: number)
that you specify amount to send with its appropriate unit; each of one returns Observable<TEtherTransactionResponse>
. It launch to sending transaction after subscribing to the obserable.EtherWalletService
is a service concern all about wallet.
account$
is Observable<string>
that emits the address wallet of the connected accountbalance$
is Observable<TEtherBigNumber>
that emits a TEtherBigNumber
value, it concerns balance of the connected wallettransactionCount$
is Observable<number>
, it emits number
value of transaction countAnd for methods, there is the following:
connectWallet()
returns Observable<string[]>
tries to connect the current wallet and returns the current connected wallet in arraygetBalanceOf(addressWallet: string)
is Observable<TEtherBigNumber>
that emits balance information of the provided address walletgetTransactionCountOf(addressWallet: string)
is Observable<number>
that emits transaction count of the provided address walletAnd listeners event, there is the following with 2 definitions each:
onAccountChange()
returns Observable<string[]>
that emits list of wallet connected, if for example we switch from an account/address wallet to another one.Or with second definition
onAccountChange(fn: (accounts: string[]) => void)
returns void
, you need to provide a callback function with 1 arguments of account/address wallet list, it does emit list of wallet connected, if for example we switch from an account/address wallet to another one.
onConnect()
returns Observable<boolean>
that emits true
if wallet is connected, false
if not
Or with second definition
onConnect(fn: (isConnected: boolean) => void)
returns void
, you need to provide a callback function with 1 arguments of boolean value is account connected or not; true
if wallet is connected, false
if not
onDisconnect()
returns Observable<void>
that emits a void
value if wallet has disconnected
Or with second definition
onDisconnect(fn: () => void)
returns void
, you need to provide a callback function without arguments; that emits a void
value if wallet has disconnectedAEtherContract
is an abstract class and a token to either to implement with 0 meethod to implement or to inject, the second case it will give you an instance of Contract.
Note: This abstract class is available if TEtherConfigurationRoot
is provided.
AEtherProvider
is an abstract class and a token to either to implement with 0 meethod to implement or to inject, the second case it will give you an instance of Web3Provider.
AEtherSigner
is an abstract class and a token to either to implement with 0 meethod to implement or to inject, the second case it will give you an instance of JsonRpcSigner.
ACustomContract
is an abstract class to implement with your own custom smart contract call or transaction method, with Observable
as return type. It has a super protected member calld contract
that gives you access to the deployed smart contract provided in forRoot static method configuration.
ContractInjectable
is a class decorator, it must annotates a class that extends ACustomContract
. It has a parameter just like Injectable
a scope to provide it in, by default is root
.
You can interact with your custom deployed contract, like in the example below:
...
import { ACustomContract, ContractInjectable } from '@ashetm/ng-ether';
...
@ContractInjectable() // Compulsory, to annotate it
export class CustomContract extends ACustomContract { // Compulsory, extends ACustomContract
test(): Observable<any> {
return from(this.contract["decimals"]());
}
}
LOOKING FOR MAINTAINER OR IF THERE IS AN ISSUE OR ANY IDEA TO ADD. PLEASE CREATE ISSUE IN GITHUB REPOSITORY.
FAQs
``@ashetm/ng-ether`` is a library that simplify manipulation of library ``ethers``, and has a good interaction with Angular with its stream based with ``RXJS``. It provides also a test module that provide mock of ``window.ethereum`` in a token (see below)
The npm package @ashetm/ng-ether receives a total of 1 weekly downloads. As such, @ashetm/ng-ether popularity was classified as not popular.
We found that @ashetm/ng-ether demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.