My contract in remix runs ok, and I use truffle to deploy the contract successfully. When I call a contract function to assign values to mapping through the contract address using go, both geth console and go console show it is sucessful, however I call another function to get the data in the contract, I get nothing, and there is no error.

My contract:

pragma solidity ^0.5.0;
contract QC6 {
mapping (uint => Que) public pic;
uint[] public idxs;
struct UserInfo {
    uint index;
    uint[] ids;

struct Que {
    string que;
    string des;
    string asker;
    uint timestamp;
    uint idx;
    uint ansNum;
    string[100] ans;

mapping (address => UserInfo) public userInfos;
uint public x = 0;

function submitQue(string memory que, string memory des, uint timestamp, string memory asker) payable public {
    uint re = x;
    x = re + 1;
    string[100] memory s;
    pic[re] = Que({que:que, des:des, timestamp:timestamp,idx: 0, ans: s, ansNum:0, asker:asker});
    //UserInfo storage info = userInfos[askerAddr];
    //info.index = info.ids.length;
    //info.ids[info.index] = re;


function submitAns(uint id, string memory an) public {
    Que storage p = pic[id];
    p.ans[p.ansNum] = an;
    p.ansNum = p.ansNum + 1;
    pic[id] = p;

function getQuestion(uint id) public view returns (string memory title,
    string memory des,
    string memory account,
    uint timestamp,
    uint idx, uint ansNum) {
    Que storage re = pic[id];
    return (re.que, re.des,re.asker, re.timestamp, re.idx, re.ansNum);

 function getAnswers(uint id, uint idx) view public returns (string memory) {
    string memory re = pic[id].ans[idx];
    return (re);


my go code:

conn, err := ethclient.Dial(hostRPC)
if err != nil {
CClient = conn

contract, err := NewQC6(common.HexToAddress(contractAddr), conn)
if err != nil {
    log.Fatalf("could not get contract: %v", err)
} else {
    fmt.Println("get ok")

QC = contract

tx, err := cc.QC.SubmitQue(cc.GetKey(), p.Question, p.Answer, big.NewInt(p.Utime), p.Account)

if err != nil {
} else {
    fmt.Println("submit success, from:", p.Account)
    fmt.Println("wait, hash:", tx.Hash())
receipt, err := bind.WaitMined(context.Background(), cc.CClient, tx)
fmt.Println("ok, hash", receipt.TxHash)

tt, err := cc.QC.Pic(&bind.CallOpts{Pending: true}, big.NewInt(0))
if err != nil {
} else {

size, err := cc.QC.X(&bind.CallOpts{Pending: true})
if err != nil {
    if size == nil {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.