智能合约 eos.js 调用 Helloword 合约都失败了

AlitteXin · 2018年10月13日 · 最后由 gk5 回复于 2018年10月15日 · 329 次阅读

经过漫长的学习,大多数经历跟环境在做斗争,从EOS的环境搭建到各种命令的学习,到最后智能合约的部署和调用都成功了

后面尝试做一个简单的DAPP,就是他
ping-eos

合约嘛,我都部署了,命令行里都可以成功

就是用eos.js去调用就是不行,一直觉得是配置问题

const EOS_CONFIG = {
  contractName: "pingacount", //合约执行账户
  contractSender: "pingatest", // 合约测试账户
  clientConfig: {

    keyProvider: ['5HwAGYEZp4EXndzogy32tp3WYEYRVbAp53M9LS4kbWbG745H4u2'], // 合约测试账户Private key
    httpEndpoint: 'http://127.0.0.1:8888' // EOS http endpoint
  }
}

class Pingdemo extends React.Component {
  constructor(props) {
    super(props)
    this.state = { pingStatus: false }
  }

  sendPing() {
    this.setState({ pingStatus: 'loading' })

    let eosClient = EOS.Localnet(EOS_CONFIG.clientConfig)

    eosClient.contract(EOS_CONFIG.contractName)
      .then((contract) => {
        contract.ping(EOS_CONFIG.contractSender, { authorization: [EOS_CONFIG.contractSender] })
          .then((res) => { this.setState({ pingStatus: 'success' }) })
          .catch((err) => { this.setState({ pingStatus: 'fail' }); console.log(err) })
      })
  }

看js代码没毛病啊,就是调不通,错误如下:

apigen.js:97 POST http://127.0.0.1:8888/v1/chain/push_transaction 500 (Internal Server Error)

apigen.js:118 api error => http://127.0.0.1:8888/v1/chain/push_transaction {"compression":"none","transaction":{"expiration":"2018-10-13T07:57:15","region":0,"ref_block_num":6156,"ref_block_prefix":4058033983,"max_net_usage_words":0,"max_kcpu_usage":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"pingacount","name":"ping","authorization":[{"actor":"pingatest","permission":"active"}],"data":"0000c85865c3a6ab"}]},"signatures":["EOSJuKqks2PbRxwarrT5dReftvxcGmn2bqHN28TqWG7kAF6sbKi1Y5S5bhaPfqQJpoKXFKVfqS4diXxtehsbySZUSsBeWZgUV"]} Error: {"code":500,"message":"Internal Service Error","error":{"code":3010011,"name":"packed_transaction_type_exception","what":"Invalid packed transaction","details":[{"message":"Invalid packed transaction","file":"chain_plugin.cpp","line_number":770,"method":"push_transaction"},{"message":"pivot != std::string::npos: No delimiter in string, cannot determine type: EOSJuKqks2PbRxwarrT5dReftvxcGmn2bqHN28TqWG7kAF6sbKi1Y5S5bhaPfqQJpoKXFKVfqS4diXxtehsbySZUSsBeWZgUV","file":"signature.cpp","line_number":20,"method":"parse_base58"},{"message":"Failed to deserialize variant","file":"abi_serializer.hpp","line_number":516,"method":"from_variant"}]}}
    at eval (apigen.js:102)
"code":3010011,"name":"packed_transaction_type_exception","what":"Invalid packed transaction","details":[{"message":"Invalid packed transaction"

错误关键在这里

希望有大佬知道的,路过的,回答一下呗

共收到 5 条回复

Invalid packed transaction 这个是因为交易内容不对还是签名不对?

@strahe 大佬 很奇怪的事 我就是测试合约 不牵扯到交易内容 ,获取是私钥不对

@lome 你看看知道怎么回事吗

你看看你的http endpoint的rpc接口可以用吗?
http://127.0.0.1:8888/v1/chain/get_info

你用eosjs的话感觉需要改127.0.0.1这个IP为你本机IP吧

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册