Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

15.6. truffle console

15.6.1. 獲取賬號列表

			
truffle(development)> web3.eth.accounts
[ '0x8232ef29d29f46d3621350ab7097604247ed4830',
  '0x3c1ba8b80b9a8697f2e34194c2a73a93105be23d' ]
  
truffle(development)> web3.eth.getAccounts(function(err,res) { accounts = res; });
undefined
truffle(development)> accounts[0]
'0x8232ef29d29f46d3621350ab7097604247ed4830'
			
			

15.6.2. 餘額

			
truffle(development)> web3.eth.getBalance(web3.eth.accounts[0])
BigNumber { s: 1, e: 22, c: [ 206250000 ] }
			
			

15.6.3. 實例化合約

			
var contract;
Conference.deployed().then(function(instance){contract=instance;});
			
			

15.6.4. 訪問 public 變數

			
truffle(development)> contract.quota.call().then(console.log);
BigNumber { s: 1, e: 1, c: [ 50 ] }
undefined			
			
			

15.6.5. 調用 public 函數

			
var contract;
Conference.deployed().then(function(instance){contract=instance;});
contract.buyTicket();
			
			

函數參數 call(param1, param2 ......)

			
truffle(development)> contract.balanceOf.call(web3.eth.accounts[0]).then(console.log);
BigNumber { s: 1, e: 27, c: [ 12000000000000 ] }
undefined