使用geth發(fā)送交易
更新時間:
啟動一個連接到節(jié)點的交互控制臺,您可以參考文檔開啟geth交互控制臺來建立一個交互控制臺
創(chuàng)建一個以太坊賬戶,如果您已經(jīng)在節(jié)點上創(chuàng)建了以太坊賬戶,可以使用已有賬戶完成后續(xù)操作
// create a account that use empty password
var account = personal.newAccount("");
// using an existing account in node
// var account = eth.accounts[0]
// unlock account for 300 seconds with empty password
personal.unlockAccount(account, "", 300);
// set it as default account
web3.eth.defaultAccount = account;
指定智能合約的地址和ABI,并發(fā)起調(diào)用。您可以參考部署智能合約中的步驟來部署智能合約,并獲取智能合約的地址和ABI。
// your contract address that you want to call
var address = "0x0000000";
// your contarct ABI that address corresponds to
var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"type":"constructor"}];
var contract = eth.contract(abi).at(address)
// call get method of demo contract
contract.get()
// call set method of demo contract, and create a new transaction
contract.set(999)
文檔內(nèi)容是否對您有幫助?