Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | Github | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

12.3. 交易

12.3.1. 发送 ETH

			
from web3 import Web3
web3 = Web3(Web3.IPCProvider("~/Library/Ethereum/geth.ipc"))	

fromAddress = '0xf56b81a2bcb964D2806071e9Be4289A5559BB0fA'
toAddress = '0x997e5CA600E19447D0B82aFBf9c7F00De2B39B16'
value = 0.0001

web3.personal.unlockAccount(fromAddress, '12345678')
web3.eth.sendTransaction({'to': toAddress, 'from': fromAddress, 'value': value})
			
			

12.3.2. 签名发送 ETH

			
from web3 import Web3
web3 = Web3(Web3.HTTPProvider("https://ropsten.infura.io/CsS9shwaAab0z7B4LP2d"))	

privateKey = '8D16063C3F665A6FB37195D18968E63CC04CEE4BFB1B98C184121D4C31D9875E'
fromAddress = "0xb3cedc76e75fcd278c988b22963c2f35c99c10b7"
toAddress = '0x997e5CA600E19447D0B82aFBf9c7F00De2B39B16'
amount = 0.0001

signed_txn = web3.eth.account.signTransaction(dict(
    nonce=web3.eth.getTransactionCount(fromAddress),
    gasPrice=web3.eth.gasPrice,
    gas=21000,
    to=toAddress,
    value=amount,
    data=b'',
  ),
  private_key,
)
web3.eth.sendRawTransaction(signed_txn.rawTransaction)