Web3 custom-element, brings the whole api and a bit more.
npm i --save @vandeurenglenn/custom-web3
<custom-web3></custom-web3>
<script type="module">
import '@vandeurenglenn/custom-web3'
customElements.whenDefined('custom-web3').then(() => {
const abi = [{}]
document.querySelector('custom-web3').addContract('contract name', 'contract address', abi)
})
</script>
name
contract name (makes the contract available in globalThis)
address
contract address
abi
contract abi
const name = 'mycontract'
document.querySelector('custom-web3').addContract('mycontract', '0x0...', [{}])
globalThis.contracts.mycontract // full contract like your used to
await globalThis.mycontract.methods.balance('0x0...').call() // 0
globalThis.mycontract // Abi proxy (removes the need to .call())
await globalThis.mycontract.balance('0x0...') // 0
Show Dialog and connect account (Metamask etc)
document.querySelector('custom-web3').connect()
Returns connected accounts
document.querySelector('custom-web3').accounts
If not supported, imports our web3 version
document.querySelector('custom-web3').isSupported()