@vandeurenglenn/custom-web3

1.3.0 • Public • Published

Build Status npm David npm node

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()

Powered by

Build/Packaged with

Package Sidebar

Install

npm i @vandeurenglenn/custom-web3

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

1.41 MB

Total Files

8

Last publish

Collaborators

  • vandeurenglenn