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

9.6. truffle console

9.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'
			
			

9.6.2. 余额

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

9.6.3. 实例化合约

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

9.6.4. 访问 public 变量

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

9.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