响应参数:
{"status": "success","data": {"tx_id": "5ef27b930646d468bbb436d3406972ff201aa63702518f777e31dd6a2147dddc"}}
?
用上面返回的tx_id去比原的浏览器中去查看交易详情,就可以查看到我们上传的数据
文章插图
参考代码:
package mainimport ("bytes""encoding/json""fmt""io/ioutil""net/http")//build-transaction params//https://bytom.github.io/mydoc_RPC_call.cn.html#build-transactiontype BytomAccount struct {AccountId string `json:"account_id"`Amountint`json:"amount"`AssetIdstring `json:"asset_id"`//Arbitrary string `json:"arbitrary"`Type string `json:"type"`}type BytomAccount1 struct {AccountId string `json:"account_id"`Amountint`json:"amount"`AssetIdstring `json:"asset_id"`Arbitrary string `json:"arbitrary"`Typestring `json:"type"`}type BaseTransaction struct{}type TransactionParams struct {BaseTransaction *BaseTransaction `json:"base_transaction"`Actions[]interface{}`json:"actions"`Ttlint`json:"ttl"`TimeRangeint`json:"time_range"`}//sign-transaction params//https://bytom.github.io/mydoc_RPC_call.cn.html#build-transactiontype Transaction struct {}type SignParams struct {Passwordstring`json:"password"`Transaction Transaction `json:"transaction"`}//submit-transaction//https://bytom.github.io/mydoc_RPC_call.cn.html#build-transactiontype SubmitParams struct {RawTransaction string `json:"raw_transaction"`}type SubmitResponse struct {TxId string `json:"tx_id"`}func main() {account1, account2, account3 := BytomAccount{}, BytomAccount{}, BytomAccount1{}account1.AccountId = "0KTCS3R5G0A02"account1.Amount = 10000000account1.AssetId = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"account1.Type = "spend_account"account2.AccountId = "0KTCS3R5G0A02"account2.Amount = 100account2.AssetId = "608037f96e8d1613d900c67a0730cc90e2a03311fb7d091588f7eb551a6103cd"account2.Type = "spend_account"account3.AccountId = "0KTCS3R5G0A02"account3.Amount = 100account3.AssetId = "608037f96e8d1613d900c67a0730cc90e2a03311fb7d091588f7eb551a6103cd"account3.Arbitrary = "77656c636f6d65efbc8ce6aca2e8bf8ee69da5e588b0e58e9fe5ad90e4b896e7958c"account3.Type = "retire"//var arrayvar actions []interface{}//append three paramsarray_actions := append(actions, account1, account2, account3)transaction_params := &TransactionParams{}transaction_params.Actions = array_actionstransaction_params.Ttl = 0transaction_params.TimeRange = 1521625823//本地测试网节点//build-transactionport := "http://127.0.0.1:9888/build-transaction"value, err := SendTransactionRetire(transaction_params, port)if err != nil {fmt.Println("err:", err)}fmt.Println("build-transaction接口返回的参数:", value)//sign-transaction//...........//submit-transaction//...........}//send post requestfunc SendTransactionRetire(params *TransactionParams, portstring) (v interface{}, err error) {//以本地测试网节点连接ParamsStr, err := json.Marshal(params)if err != nil {return nil, err}jsonStr := bytes.NewBuffer(ParamsStr)fmt.Println(jsonStr)req, err := http.NewRequest("POST", port, jsonStr)req.Header.Set("Content-Type", "application/json")req.Header.Add("Accept", "application/json")client := &http.Client{}resp, err := client.Do(req)if err != nil {panic(err)}defer resp.Body.Close()var bodyBytes []byteif resp.StatusCode == 200 {bodyBytes, err = ioutil.ReadAll(resp.Body)if err != nil {return nil, err}}return string(bodyBytes), nil}
上面的代码只是build-一个步骤,另外sign-和-请求需要自己去组织参数进行请求 。请求完- 获得返回的交易hash,去区块链浏览器上查看自己的上链信息,区块链浏览器地址::8082/ 。
好了,通过以上的4个步骤,我们就可以借助比原链实现信息上链 。如果你有什么疑问或者不明白,请在我们的社区联系我们,。
- 世界上最坚硬的2种动物,子弹都打不穿,防弹衣也是这个原理吗? 世界之最质量动物
- 世界上评分最高的十部电影,中国占了一部!看看你看过哪几部 imdb收录世界之最
- 黄浦公园
- 中元节晚上可以出门吗 中元节的晚上能出门吗
- 唐太宗明诏道教在佛教之上,佛教却在唐朝盛行?
- 历史上汉武帝和司马迁:究竟谁阉割了谁?
- 世界上最壮观的「沸腾可乐」奇观1,500瓶可乐同时喷发
- 历史上神秘的谶言亡秦者胡也:胡为何者?
- 中国史上绝版帝国:上至宰相下至县令全是太监
- 揭秘史上不明生物遗骸:带翅膀的人骨