@vandeurenglenn/custom-web3
v1.3.0
Published
Web3 custom-element, brings the whole api and a bit more.
Downloads
4
Maintainers
Readme
custom-web3
Web3 custom-element, brings the whole api and a bit more.
Install
npm i --save @vandeurenglenn/custom-web3
Usage
<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>
API
addContract(name, address, abi)
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
connect()
Show Dialog and connect account (Metamask etc)
document.querySelector('custom-web3').connect()
accounts
Returns connected accounts
document.querySelector('custom-web3').accounts
isSupported
If not supported, imports our web3 version
document.querySelector('custom-web3').isSupported()