1. 星速云首页
  2. 阿里云文档

阿里云区块链服务使用geth发送交易

  1. 启动一个连接到节点的交互控制台,您可以参考文档开启geth交互控制台来建立一个交互控制台

  2. 创建一个以太坊账户,如果您已经在节点上创建了以太坊账户,可以使用已有账户完成后续操作

    1. // create a account that use empty password
    2. var account = personal.newAccount("");
    3. // using an existing account in node
    4. // var account = eth.accounts[0]
    5. // unlock account for 300 seconds with empty password
    6. personal.unlockAccount(account, "", 300);
    7. // set it as default account
    8. web3.eth.defaultAccount = account;
  3. 指定智能合约的地址和ABI,并发起调用。您可以参考部署智能合约中的步骤来部署智能合约,并获取智能合约的地址和ABI。

    1. // your contract address that you want to call
    2. var address = "0x0000000";
    3. // your contarct ABI that address corresponds to
    4. 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"}];
    5. var contract = eth.contract(abi).at(address)
    6. // call get method of demo contract
    7. contract.get()
    8. // call set method of demo contract, and create a new transaction
    9. contract.set(999)

注明:本文为星速云原创版权所有,禁止转载,一经发现将追究版权责任!

发表评论

登录后才能评论
问答社区 QQ客服
微信客服
微信客服
分享本页
返回顶部