vue3-cli-plugin A single Web3 / Ethereum provider solution for all Wallets
cd example && npm install && npm serve
vue-cli-plugin-web3modal It is based on web3modal for vuejs help developers add support for multiple providers in their apps with a simple customizable configuration.
vue add vue-cli-plugin-web3modal
OR
- Install vue-cli-plugin-web3modal NPM package
npm install --save-dev vue-cli-plugin-web3modal
# OR
yarn add vue-cli-plugin-web3modal --dev
- vue add plugin
vue invoke vue-cli-plugin-web3modal
If you add Exanple's directory structure in the configuration:
src
│ ├── App.vue
│ ├── assets
│ │ └── logo.png
│ ├── components
│ │ ├── ConnectWallteExample.vue
│ │ └── HelloWorld.vue
│ ├── hooks
│ │ └── useWallte.js
│ ├── main.js
│ ├── registerServiceWorker.js
│ └── web3
│ ├── abis.js
│ ├── chains.js
│ ├── config.js
│ ├── constants.dev.js
│ ├── constants.js
│ └── tools.js
- src/web3/config.js, providerOptions Configuration can refer to https://github.com/Web3Modal/web3modal#custom-display
const providerOptions = {
// Example with injected providers
injected: {
display: {
logo: "data:image/gif;base64,INSERT_BASE64_STRING",
name: "Injected",
description: "Connect with the provider in your Browser"
},
package: null
},
// Example with WalletConnect provider
walletconnect: {
display: {
logo: "data:image/gif;base64,INSERT_BASE64_STRING",
name: "Mobile",
description: "Scan qrcode with your mobile wallet"
},
package: WalletConnectProvider,
options: {
infuraId: "INFURA_ID" // required
}
}
};
- src/hooks/useWallte.js Here will provide web3、userAddress、chainId、networkId、resetApp、assets、getAccountAssets Wait, Please use ConnectWallteExample.vue
<script setup>
const {
onConnect,
connected,
web3,
userAddress,
chainId,
networkId,
resetApp,
assets,
getAccountAssets,
} = useWallet();
const handleWalletConnect = async () => {
await onConnect();
if (connected) {
console.log('afterConnectdWallet', connected);
}
};
const contract = computed(
() => new web3.value.eth.Contract(USDT_API, USDT_ADDRESS),
);
function approve() {
return contract.value.methods
.approve(USDT_ADDRESS, utils.toHex(utils.toWei('1000000000000000000000000000', 'gwei')))
.send({ from: userAddress.value });
}
// .....
</script>