-
//SPDX-License-Identifier: UNLICENSED pragma solidity >=0.7.0 <0.9.0; contract Send1 { function sendV1(address payable _addr) public payable { bool rst = _addr.send(11 ether); } function sendV2(address payable _addr) public payable { bool rst = _addr.send(11 ether); require(rst, "failed"); } function sendV3(address payable _addr) public { bool rst = _addr.send(11 ether); require(rst, "failed"); } function sendV4(address payable _addr) public { bool rst = payable(_addr).send(11 ether); require(rst, "failed"); } }
Deploy
creation of Send1 pending... [vm]from: 0x5B3...eddC4to: Send1.(constructor)value: 0 weidata: 0x608...70033logs: 0hash: 0x892...abe2f status true Transaction mined and execution succeed transaction hash 0x892e453378b7ed64693525719da766ae41b48c6ffb0f6832913b33ef8ffabe2f from 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 to Send1.(constructor) gas 307144 gas transaction cost 267081 gas execution cost 267081 gas input 0x608...70033 decoded input {} decoded output - logs [] val 0 wei transact to Send1.sendV1 pending ...
SendV1
account: 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db
value: 30 ether대상: 0xd9145CCE52D386f254917e481eB44e9943F39138
transact to Send1.sendV1 pending ... [vm]from: 0x4B2...C02dbto: Send1.sendV1(address) 0xd91...39138value: 30000000000000000000 weidata: 0x184...35cb2logs: 0hash: 0x627...a1260 status true Transaction mined and execution succeed transaction hash 0x6271cec922c8aea9dfce73915cc59529e7c0cee4e734119ec39afd9ebc7a1260 from 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db to Send1.sendV1(address) 0xd9145CCE52D386f254917e481eB44e9943F39138 gas 35915 gas transaction cost 31230 gas execution cost 31230 gas input 0x184...35cb2 decoded input { "address _addr": "0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2" } decoded output {} logs [] val 30000000000000000000 wei
출금은 약 30 ether(+수수료차이) 빠져 나갔지만,
입금은 11 ether가 되어 잔고 111 ether가 되었다.
Contract에는 0에서 19 Eth로 남아있다.만약 Contract에 0 Eth고 Value에 10 Eth를 입력할 경우, Contract는 9 Eth(+수수료)가 되고 목적 지갑에는 11 ether를 넣을 수 없으므로 입금이 안 되고 transact은 성공을 출력하고 끝난다.
만약 Contract에 0 Eth고 Value에 30 Eth를 입력할 경우, Contract는 18 Eth가 되고 목적 지갑에는 11 ether를 넣을 수 있으므로 입금되고 transact은 성공을 출력하고 끝난다.
SendV2
account: 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db
value: 30 ether대상: 0xd9145CCE52D386f254917e481eB44e9943F39138
transact to Send1.sendV2 pending ... [vm]from: 0x4B2...C02dbto: Send1.sendV2(address) 0xd91...39138value: 30000000000000000000 weidata: 0x4fe...35cb2logs: 0hash: 0x03f...9fd09 status true Transaction mined and execution succeed transaction hash 0x03f1bf4f76a29372a422c0e16e00c4afaff50513d052e776f2e8cf8112a9fd09 from 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db to Send1.sendV2(address) 0xd9145CCE52D386f254917e481eB44e9943F39138 gas 35985 gas transaction cost 31291 gas execution cost 31291 gas input 0x4fe...35cb2 decoded input { "address _addr": "0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2" } decoded output {} logs [] val 30000000000000000000 wei
만약 Contract에 0 Eth고 Value에 10 Eth를 입력할 경우, SendV1과 달리 Contract에 Eth는 변화가 없고 목적 지갑에도 11 ether를 넣을 수 없으므로 입금이 안 되고 transact은 실패를 출력하고 끝난다.
예제: Contract 0Eth, Value 10Ethtransact to Send1.sendV2 pending ... [vm]from: 0x4B2...C02dbto: Send1.sendV2(address) 0xd91...39138value: 10000000000000000000 weidata: 0x4fe...35cb2logs: 0hash: 0x5b7...001b3 status false Transaction mined but execution failed transaction hash 0x5b7114c52b10b4fb65f7e6e2dbb2e14eb2d39270ad0d789c12d3def592b001b3 from 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db to Send1.sendV2(address) 0xd9145CCE52D386f254917e481eB44e9943F39138 gas 3000000 gas transaction cost 31576 gas execution cost 31576 gas input 0x4fe...35cb2 decoded input { "address _addr": "0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2" } decoded output {} logs [] val 10000000000000000000 wei transact to Send1.sendV2 errored: VM error: revert. revert The transaction has been reverted to the initial state. Reason provided by the contract: "failed". Debug the transaction to get more information.
만약 Contract에 7 Eth고 Value에 5 Eth를 입력할 경우, Contract에 0 Eth, 목적 지갑에는 11 ether를 넣을 수 있으므로 입금이 되고 transact은 성공을 출력하고 끝난다.
'Blockchain' 카테고리의 다른 글
Solidity What does _ (underscore) (0) 2023.01.08 Geth Ethereum client (0) 2023.01.07 ERC721 관련 (0) 2023.01.07 Truffle 예제 'pet-shop' (0) 2023.01.03 Nodejs + Vsc에서 remixd 사용 (0) 2023.01.02 Solidity balance Ex1 (0) 2023.01.02 Solidity Ether units (ether, gwei, wei) Ex1 (0) 2023.01.02 Solidity 화폐 수신 - fallback, receive (0) 2023.01.02