A Multichain crypto wallet library that supports Ethereum, Solana and other EVM compatible blockchains.
npm install multichain-crypto-wallet
Using yarn,
yarn add multichain-crypto-wallet
const multichainWallet = require('multichain-crypto-wallet');
import multichainWallet from 'multichain-crypto-wallet';
The following methods are available with this SDK:
- Multichain Crypto Wallet
This method creates a new wallet. The method accepts a payload object as the parameter. The parameter of this payload is:
// Creating an Ethereum wallet.
const wallet = await multichainWallet.createWallet({
derivationPath: "m/44'/60'/0'/0/0", // Leave empty to use default derivation path
network: 'ethereum',
});
// Creating a Solana wallet.
const wallet = await multichainWallet.createWallet({
derivationPath: "m/44'/501'/0'/0'", // Leave empty to use default derivation path
network: 'solana',
});
{
address: '0xfBE11AC0258cc8288cA24E818691Eb062f7042E9',
privateKey: '0xfdf745f45d1942feea79b4c0a3fc1ca67da366899f7e6cebaa06496806ca8127',
mnemonic: 'net idle lava mango another capable inhale portion blossom fluid discover cruise'
}
This gets the balance of the address passed in. The method accepts an object as the parameter. The parameters for this object depeding on the kind of balance to be gotten is in the form:
// Get the ETH balance of an address
const data = await multichainWallet.getBalance({
address: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
});
// Get the SOL balance of an address
const data = await multichainWallet.getBalance({
address: 'DYgLjazTY6kMqagbDMsNttRHKQj9o6pNS8D6jMjWbmP7',
network: 'solana',
rpcUrl: 'https://api.devnet.solana.com',
});
// Get the balance of an ERC20 token.
const data = await multichainWallet.getBalance({
address: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
network: 'ethereum',
rpcUrl: 'https://rpc.ankr.com/eth',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
});
// Get the balance of a token on Solana.
const data = await multichainWallet.getBalance({
address: '5PwN5k7hin2XxUUaXveur7jSe5qt2mkWinp1JEiv8xYu',
tokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
network: 'solana',
rpcUrl: 'https://rpc.ankr.com/solana',
});
{
balance: 2;
}
This generates a wallet from Mnemonic phrase. The method accepts an object as the parameter. The parameters that this object takes are:
// Generate an Ethereum wallet from mnemonic.
const wallet = await multichainWallet.generateWalletFromMnemonic({
mnemonic:
'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat',
derivationPath: "m/44'/60'/0'/0/0", // Leave empty to use default derivation path
network: 'ethereum',
});
// Generate a Solana wallet from mnemonic.
const wallet = await multichainWallet.generateWalletFromMnemonic({
mnemonic:
'base dry mango subject neither labor portion weekend range couple right document',
derivationPath: "m/44'/501'/0'/0'", // Leave empty to use default derivation path
network: 'solana',
});
{
address: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
privateKey: '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',
mnemonic: 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'
}
This gets the address from the private key passed in. The method accepts an object as the parameter. The parameters that this object takes are:
// Get the address from the private key on the Ethereum network.
const address = await multichainWallet.getAddressFromPrivateKey({
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
network: 'ethereum',
});
// Get the address from the private key on the Solana network.
const address = await multichainWallet.getAddressFromPrivateKey({
privateKey:
'bXXgTj2cgXMFAGpLHkF5GhnoNeUpmcJDsxXDhXQhQhL2BDpJumdwMGeC5Cs66stsN3GfkMH8oyHu24dnojKbtfp',
network: 'solana',
});
{
address: '0x1C082D1052fb44134a408651c01148aDBFcCe7Fe';
}
This gets the transcation receipt of a transaction from the transaction hash. The method accepts an object as the parameter. The parameters that this object takes are:
// Get the transaction receipt on Ethereum network.
const receipt = await multichainWallet.getTransaction({
hash: '0x5a90cea37e3a5dbee6e10190ff5a3769ad27a0c6f625458682104e26e0491055',
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
});
// Get the transaction receipt on Solana network.
const receipt = await multichainWallet.getTransaction({
rpcUrl: 'https://api.devnet.solana.com',
hash:
'CkG1ynQ2vN8bmNsBUKG8ix3moUUfELWwd8K2f7mmqDd7LifFFfgyFhBux6t22AncbY4NR3PsEU3DbH7mDBMXWk7',
network: 'solana',
});
{
receipt: {
object;
}
}
This transfers the amount of tokens from the source address to the destination address It takes in an object as the parameter. It allows for the transfer of the following:
Allows for the transfer of ETH, and overriding of transactions.
// Transferring ETH from one address to another.
const transfer = await multichainWallet.transfer({
recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
amount: 1,
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
gasPrice: '10', // Gas price is in Gwei. Leave empty to use default gas price
});
// Transferring ERC20 tokens from one address to another.
const transfer = await multichainWallet.transfer({
recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
amount: 10,
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
gasPrice: '10', // Gas price is in Gwei. leave empty to use default gas price
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
});
The optional parameters that the object takes in are: gas price and nonce.
- The gas price is the price of gas in Gwei. The higher the gas price, the faster the transaction will be. It's best to use a higher gas price than the default.
- The nonce is the number of transactions that have been sent from the source address and is used to ensure that the transaction is unique. The transaction is unique because the nonce is incremented each time a transaction is sent.
// Overriding pending ETH transaction.
const transfer = await multichainWallet.transfer({
recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
amount: 0,
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
gasPrice: '10',
nonce: 1, // The pending transaction nonce
});
// Overriding ERC20 token pending transaction.
const transfer = await multichainWallet.transfer({
recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
amount: 0,
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
gasPrice: '10',
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
nonce: 1, // The pending transaction nonce
});
{
hash: '0xf2978fe918f3e28b7f57101bbc99aa9d7d2d71507ca4a08bac6dd09575527502';
}
It supports encryption of ethereum and other EVM compatible chains private keys.
// encrypt private key.
const encrypted = await multichainWallet.getEncryptedJsonFromPrivateKey({
network: 'ethereum',
privateKey:
'0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
password: 'walletpassword',
});
{
json: '{"address":"1c082d1052fb44134a408651c01148adbfcce7fe","id":"abfb9f10-165a-4b7a-935d-51729f10c310","version":3,"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"f3fac53ee2d76c293977d1af3a7d73bb"},"ciphertext":"c5034579cdf32d7a612c9a83801aad899abfebb7436712f363ecf89546bbcbce","kdf":"scrypt","kdfparams":{"salt":"78ff80ece5d681b1aecd829526388472d1889da233229fa5c1416e8f2035b7a8","n":131072,"dklen":32,"p":1,"r":8},"mac":"0f70eca6138ffe60b174308b6ab7a8a81a0d2b662e2cf5d8727443cf12af766c"}}';
}
It supports decryption of encrypted JSONs (A.K.A keystore).
// decrypting encrypted JSON.
const decrypted = await multichainWallet.getWalletFromEncryptedJson({
network: 'ethereum',
json:
'{"address":"1c082d1052fb44134a408651c01148adbfcce7fe","id":"abfb9f10-165a-4b7a-935d-51729f10c310","version":3,"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"f3fac53ee2d76c293977d1af3a7d73bb"},"ciphertext":"c5034579cdf32d7a612c9a83801aad899abfebb7436712f363ecf89546bbcbce","kdf":"scrypt","kdfparams":{"salt":"78ff80ece5d681b1aecd829526388472d1889da233229fa5c1416e8f2035b7a8","n":131072,"dklen":32,"p":1,"r":8},"mac":"0f70eca6138ffe60b174308b6ab7a8a81a0d2b662e2cf5d8727443cf12af766c"}}',
password: 'walletpassword',
});
{
privateKey: '0x0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
address: '0x1C082D1052fb44134a408651c01148aDBFcCe7Fe'
}
Allows for fetching ERC20 tokens info from compatible blockchains by the token address
// getting token info.
const info = await multichainWallet.getTokenInfo({
address: '0x7fe03a082fd18a80a7dbd55e9b216bcf540557e4',
network: 'ethereum',
rpcUrl: 'https://rinkeby-light.eth.linkpool.io',
});
{
name: 'Mocked USDT',
symbol: 'USDT',
decimals: 6,
address: '0x7fe03a082fd18a80a7dbd55e9b216bcf540557e4',
totalSupply: 1000000000000
}
Allows for the transfer of SOL and tokens.
// Transferring SOL from one address to another.
const transfer = await MultichainCryptoWallet.transfer({
recipientAddress: '9DSRMyr3EfxPzxZo9wMBPku7mvcazHTHfyjhcfw5yucA',
amount: 1,
network: 'solana',
rpcUrl: 'https://api.devnet.solana.com',
privateKey:
'bXXgTj2cgXMFAGpLHkF5GhnoNeUpmcJDsxXDhXQhQhL2BDpJumdwMGeC5Cs66stsN3GfkMH8oyHu24dnojKbtfp',
});
// Transferring a token from one address to another.
const transfer = await MultichainCryptoWallet.transfer({
recipientAddress: '9DSRMyr3EfxPzxZo9wMBPku7mvcazHTHfyjhcfw5yucA',
tokenAddress: 'DV2exYApRFWEVb9oQkedLRYeSm8ccxNReLfEksEE5FZm',
amount: 1,
network: 'solana',
rpcUrl: 'https://api.devnet.solana.com',
privateKey:
'h5KUPKU4z8c9nhMCQsvCLq4q6Xn9XK1B1cKjC9bJVLQLgJDvknKCBtZdHKDoKBHuATnSYaHRvjJSDdBWN8P67hh',
});
{
hash: '3nGq2yczqCpm8bF2dyvdPtXpnFLJ1oGWkDfD6neLbRay8SjNqYNhWQBKE1ZFunxvFhJ47FyT6igNpYPP293jXCZk';
}
Allows for fetching SPL tokens info on the solana by the token address. Note: Token has to be available on the solana token list registry
// getting token info.
const info = await multichainWallet.getTokenInfo({
address: '7Xn4mM868daxsGVJmaGrYxg8CZiuqBnDwUse66s5ALmr',
network: 'solana',
rpcUrl: 'https://api.devnet.solana.com',
cluster: 'devnet',
});
{
name: 'SimpiansDEV',
symbol: 'SIMPDEV',
address: '7Xn4mM868daxsGVJmaGrYxg8CZiuqBnDwUse66s5ALmr',
decimals: 0,
logoUrl: 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/7Xn4mM868daxsGVJmaGrYxg8CZiuqBnDwUse66s5ALmr/logo.png',
totalSupply: 10000000
}
Contributions are welcome! Kindly refer to the contribution guidelines.