npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sendeth2me

v0.0.21

Published

Handy utility to decorate a `<button>` element to send ether to a pre-defined blockchain address.

Downloads

27

Readme

SendEth2.me Button

Handy utility to decorate a <button> element to send ether to a pre-defined blockchain address.

Install

To install the latest version of SendEth2.me library issue one of the following commands from command line (according to your preference).

Node.js

yarn add sendeth2me

or

npm install sendeth2me

HTML

Link stylesheets and javascript files in the header of your HTML file as usual.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sendeth2me@latest/dist/sendeth2me.css" />
<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/sendeth2me@latest/dist/sendeth2me.es.bundled.js"
></script>

In case you have already included ethers.js in your HTML you may use the simple version of sendeth2me.es.js:

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/sendeth2me@latest/dist/sendeth2me.es.js"
></script>

Then in the body of your HTML file define a <button> with sendeth class, and a custom address attribute.

<button class="sendeth" data-address="0x778bEe312eA9674955C7C0BA5D8D68b2eB8e2C05">
  Ether please
</button>

To turn on debugging and late initialization use the isDebug and autoInit variables under sendeth2me namespace of window object like so:

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/sendeth2me@latest/dist/sendeth2me.es.bundled.js"
  onload="window.sendeth2me.isDebug = true; window.sendeth2me.autoInit = false;"
></script>
...
<script>
  window.sendeth2me.initAll();
</script>

Usage in source

Examples

See the below examples on jsfiddle which demonstrate basic usage of this library.

  • Minimal: https://jsfiddle.net/kisszoltan/aebm3nkr/
  • Complete: https://jsfiddle.net/kisszoltan/uzs3a74d/

Element content (innerHTML)

When the <button> is defined with empty content then a default Send ETH value will be rendered as button caption.

Attributes

Attributes available for <button> elements with sendeth class:

| Attribute | Mandatory | Default value | Description | | :----------- | :-------: | :-----------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | data-address | yes | null | recipient address where the amount should be sent | | data-amount | no | 0.01 | amount in ETH to be sent when clicking on the button | | data-icon | no | null | if defined with any value then the button caption will be prefixed with the official ether icon | | data-network | no | null | if defined button will only be enabled when the given network is selected in MetaMask.Possible values are: 1 - Ethereum Mainnet3 - Ropsten4 - Rinkeby137 - Matic (Polygon) Mainnet42 - Kovan80001 - Mumbai (Polygon) Testnet43114 - Avalanche (AVAX) Mainnet43113 - Avalanche (AVAX) Testnet56 - Binance Smart Chain Mainnet97 - Binance Smart Chain Testnet |

Events

| Event | Description | | :------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | success | fired when ether transaction has finished successfully event.detail will carry information about the transaction as defined by ethers.js documentation. | | failure | emitted when any exception was thrown during the send transaction. event.detail contains the whole exception object as it was thrown. |

Styling

Additionally to the sendeth class on a <button> element, an eth-icon class is added to the prefix icon. Use this class and its path, polygon and rect elements to change the icon's size and fill color as follows:

.eth-icon {
  width: 2em;
  height: 2em;
}

.eth-icon path,
.eth-icon polygon,
.eth-icon rect {
  fill: #fff;
}

button.sendeth:disabled .eth-icon path,
button.sendeth:disabled .eth-icon polygon,
button.sendeth:disabled .eth-icon rect {
  fill: #ccc;
}

There are three pre-defined colors available (default - blue, red and green) for SendEth2Me buttons. Custom colors can be defined in similar way:

button.sendeth.green {
  background-color: #98ea62;
  color: #b462ea;
}
button.sendeth.green:hover {
  background-color: #98ea62cc;
}
button.sendeth.green:active {
  background-color: #36b416;
}

Smart contract

SendEth2.me button library uses a smart contract for sending Ether (cryptocurrency) instead of simple transactions. Of course many bullshit(ish) reasons could be listed here, but mainly it is only to pinch a bite from each transaction as developer fee so 1% is held back on contract address to support maintenance and further improvements. Apart from this, the library is free to use and there will be additional features coming like: integration with different platforms/frameworks or further customization of the button, not to mention the single page application which will provide a link option to those who cannot use HTML button (for example in a YouTube video description or on Medium.com) and so much more... These all require time and time is money hence the 1% cut.

Availability

The contract is available on GitHub and for now it is deployed to:

Mainnet(s):

Test networks:

Rules

As stated above, the contract substract 1% from each transaction to fill the developer with enough coffee to maintain and further improve this library. This substract mechanism respects the following rules:

  • sent amount is 1 wei (what a supporter?!): all 1 wei is sent to the recipient
  • sent amount is less than 100 wei: 1 wei is held back on contract and the remaining is sent to the recipient
  • sent amount is more than or equal to 100 wei: 1% is held back on contract and the remaining is sent to the recipient

For visual types like me this table shows some examples:

| Amount sent | Recipient receives | Remains on contract | | :---------- | :----------------: | :-----------------: | | 1 wei | 1 wei | 0 wei | | 2 wei | 1 wei | 1 wei | | 10 wei | 9 wei | 1 wei | | 53 wei | 52 wei | 1 wei | | 100 wei | 99 wei | 1 wei | | 110 wei | 109 wei | 1 wei | | 200 wei | 198 wei | 2 wei | | 500 wei | 495 wei | 5 wei | | 1000000 wei | 990000 wei | 10000 wei | | 1 eth | 0.99 eth | 0.01 eth |