启动一个连接到节点的交互控制台,您可以参考文档开启geth交互控制台来建立一个交互控制台
创建一个以太坊账户,如果您已经在节点上创建了以太坊账户,可以使用已有账户完成后续操作
// 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,并发起调用。您可以参考部署私有智能合约中的步骤来部署智能合约,并获取智能合约的地址和ABI。
注意:发送私有交易的
privateFor
参数必须与您部署私有智能合约时的参数保持一致,否则会导致智能合约终态不一致。// tx-mangager public key list; it should be same with the list that when your deploy the private contract
var privateFor = ["WLyCI0x1NBdy2VI4IdmxGYhRP7PKGL6wD87iN5vKp3w="];
// your private 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 private transaction
contract.set(999, {from: account, privateFor: privateFor })
文档内容是否对您有帮助?