Skip to content

Web3 custom-element, brings the whole api and a bit more.

License

Notifications You must be signed in to change notification settings

VandeurenGlenn/custom-web3

Repository files navigation

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

About

Web3 custom-element, brings the whole api and a bit more.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published