0.0.21 • Published 2 years ago

sendeth2me v0.0.21

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
2 years ago

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.

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:

AttributeMandatoryDefault valueDescription
data-addressyesnullrecipient address where the amount should be sent
data-amountno0.01amount in ETH to be sent when clicking on the button
data-iconnonullif defined with any value then the button caption will be prefixed with the official ether icon
data-networknonullif 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

EventDescription
successfired when ether transaction has finished successfully event.detail will carry information about the transaction as defined by ethers.js documentation.
failureemitted 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 sentRecipient receivesRemains on contract
1 wei1 wei0 wei
2 wei1 wei1 wei
10 wei9 wei1 wei
53 wei52 wei1 wei
100 wei99 wei1 wei
110 wei109 wei1 wei
200 wei198 wei2 wei
500 wei495 wei5 wei
1000000 wei990000 wei10000 wei
1 eth0.99 eth0.01 eth
0.0.20

2 years ago

0.0.21

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago