Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@amfi/connect-wallet
Advanced tools
Connect Crypto Wallet by using WalletLink, KardiaChain, MetaMask browser extentions or mobile application and WalletConnect service by scanning Wallet Qr-code.
This package provides the ability to connect Wallets to website or application via MetaMask extension (through a browser or the mobile application) and WalletConnect service using QR code scanner.
Worked only with MetaMask and WalletConnect
NPM: npm install @amfi/connect-wallet
Yarn: yarn add @amfi/connect-wallet
import { ConnectWallet } from '@amfi/connect-wallet';
const connectWallet = new ConnectWallet();
addChains([chains])
method.If you need to add custom blockhain use addChains(...chain)
method before you create connect.
Usage example:
const chains: IChain[] = [
...
{
name: 'binance',
chainID: 56,
hex: '0x38',
},
{
name: 'binance-test',
chainID: 97,
hex: '0x61',
},
...
];
...
const chainsInfo = this.connectWallet.addChains(this.chains); // will return chains that added into connectwallet, this method not async.
Where:
name
- blockchain name.
chainID
- blockchain id.
hex
- blockchain id in hex format.
connectWallet.connect(provider, network, settings)
method.Example configuration:
Want use Ethereum mainnet? Set useProvider:
infura
and provide mainnet Infura. Remove rpc if it needed.
{
wallets: ['MetaMask', 'WalletConnect'],
network: {
name: 'Ropsten',
chainID: 3
},
provider: {
MetaMask: {
name: 'MetaMask'
},
WalletConnect: {
name: 'WalletConnect',
useProvider: 'rpc',
provider: {
infura: {
infuraID: 'PASS_HERE_INFURA_ID',
},
rpc: {
rpc: {
3: "PASS_HERE_BLOCKCHAIN_RPC" // if use Ethereum rpc, pass full Infura URL with Infura Id
},
chainId: 3
},
},
},
},
settings: {
providerType: true
},
}
RPC configuration:
rpc: {
rpc: {
// if use Ethereum rpc, pass full Infura URL with Infura Id
[BLOCKCHAIN_NUMBER]: "BLOCKCHAIN_RPC",
[BLOCKCHAIN_NUMBER]: "BLOCKCHAIN_RPC",
...
[BLOCKCHAIN_NUMBER]: "BLOCKCHAIN_RPC"
},
// What Blockchain need to use
chainId: BLOCKCHAIN_NUMBER
},
Where:
BLOCKCHAIN_NUMBER
- blockchain/network/chain ID, for example ropsten = 3, rinkeby = 4, and etc. Used to identify what kind of blockhain need to use.
BLOCKCHAIN_RPC
- Blockhain URL.
chainId
===rpc.BLOCKCHAIN_NUMBER
connect()
.You need to pass 3 configuration options: provider, network, settings.
MetaMask:
{
name: string;
}
Wallet Connect:
{
name: string;
useProvider?: string;
provider?: {
infura?: {
infuraID?: string;
}
rpc?: {
rpc: {
[index: number]: string;
};
chainId?: number;
};
};
}
{
name: string;
chainID: number;
}
Where:
name
- blockchain name.
chainID
- blockchain id.
All parameters required
{
providerType?: boolean;
}
Where:
providerType
- show in response your provider type: MetaMask or WalletConnect.
connectWallet.connect(provider, network, settings).then(
(connected: boolean) => console.log('connect wallet: ', connected),
(err: any) => console.log('connect wallet error: ', err)
);
addContract()
method to add contract in Connect Wallet.You can pass 3 parameters in method addContract
: ContractName, address, abi.
interface:
{
name: string;
address: string;
abi: Array<any>;
}
ContractName
(name
) - use for identify your contract in Connect Wallet, for example you add two Staking contracts and one Token contract, so you can create 3 addContract methods and pass in each one params:
{
"ContractName": "Staking1",
"ContractName": "Staking2",
"ContractName": "Token"
}
address
- contract address.
abi
- contact ABI.
Example:
connectWallet.addContract({'Staking1', '0x0000000000000000', ABI[]});
connectWallet.addContract({'Staking2', '0x0000000000000000', ABI[]});
connectWallet.addContract({'Token', '0x0000000000000000', ABI[]});
contract()
.ContractName
- pass your contact name that was added in step 5.
Example:
connectWallet
.contract('Staking1')
.stakeStart('123')
.send({ from: '0x000000....' })
.then((tx: any) => console.log(tx));
connectWallet
.contract('Staking2')
.stakeStart('123')
.send({ from: '0x000000....' })
.then((tx: any) => console.log(tx));
connectWallet
.contract('Token')
.methods.balanceOf('0x0000000,,,')
.call()
.then(
(balance: string) => console.log(balance),
(err: any) => console.log(err)
);
getAccounts()
method.When connect are established via method getAccounts()
can get user wallet account information. Also with user information can get what provider are used.
connectWallet.getAccounts().subscribe(
(user: any) => console.log('user account: ', user),
(err: any) => console.log('user account error: ', err)
);
txCheck()
method.Provide transaction Hash to check if transaction are in blockchain or not.
Example:
connectWallet.txCheck('TX_HASH').then(
(info: any) => console.log('info: ', info),
(err: any) => console.log('info tx error:', err)
);
currentWeb3()
method.Get current Web3 and access to all Web3 functions.
Example:
const currentWeb3 = connectWallet.currentWeb3();
FAQs
Connect Crypto Wallet by using CoinbaseWallet (WalletLink), KardiaChain, MetaMask browser extentions or mobile application and WalletConnect service by scanning Wallet Qr-code.
The npm package @amfi/connect-wallet receives a total of 3 weekly downloads. As such, @amfi/connect-wallet popularity was classified as not popular.
We found that @amfi/connect-wallet demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.