JavaScript Wyślij Ethereum
<form>
<input id="eth" name="eth" type="number" value="0.01">
<input id="recipient" name="recipient" type="text">
<button>Send Ethereum</button>
</form>
<!-- Using Ethers.JS -->
<script src="https://unpkg.com/[email protected]/dist/ethers.umd.min.js"></script>
<script>
(async function init(){
if ( !window.ethereum ){
throw new Error("No crypto wallet found!");
}
const form = document.querySelector("form");
form.addEventListener("submit", async (e)=>{
e.preventDefault();
try {
await window.ethereum.send("eth_requestAccounts");
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const recipient = ethers.utils.getAddress(form.recipient.value);
const tx = await signer.sendTransaction({
to: recipient,
value: ethers.utils.parseEther(form.eth.value)
});
console.log({
from: tx.from,
to: tx.to,
hash: tx.hash
});
} catch(e){
console.error(e.message);
}
});
}());
</script>
KostasX