1

I have created a very simple front end to display the borrower name. I deployed the contract Borrower on Rinkeby. I can run the application if I access the variable borrowerName using the following .js code:

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import './main.html';

contractAddress = "0x7f3bdc7f93b0dfc1939669d35922d65bbc5953e4"

ABIArray = [
    {
        "constant": true,
        "inputs": [],
        "name": "getThisBalance",
        "outputs": [
            {
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "getName",
        "outputs": [
            {
                "name": "",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "borrowerName",
        "outputs": [
            {
                "name": "",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [
            {
                "name": "_borrowerName",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "constructor"
    }
]

data = "0x6060604052341561000f57600080fd5b604051610442380380610442833981016040528080518201919050508060009080519060200190610041929190610048565b50506100ed565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008957805160ff19168380011785556100b7565b828001600101855582156100b7579182015b828111156100b657825182559160200191906001019061009b565b5b5090506100c491906100c8565b5090565b6100ea91905b808211156100e65760008160009055506001016100ce565b5090565b90565b610346806100fc6000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806317d7de7c1461005c5780633655394a146100ea5780638e8cf4a814610178575b600080fd5b341561006757600080fd5b61006f6101a1565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100af578082015181840152602081019050610094565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100f557600080fd5b6100fd610249565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013d578082015181840152602081019050610122565b50505050905090810190601f16801561016a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561018357600080fd5b61018b6102e7565b6040518082815260200191505060405180910390f35b6101a9610306565b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561023f5780601f106102145761010080835404028352916020019161023f565b820191906000526020600020905b81548152906001019060200180831161022257829003601f168201915b5050505050905090565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102df5780601f106102b4576101008083540402835291602001916102df565b820191906000526020600020905b8154815290600101906020018083116102c257829003601f168201915b505050505081565b60003073ffffffffffffffffffffffffffffffffffffffff1631905090565b6020604051908101604052806000815250905600a165627a7a723058204f28f438e6dd5084db8ce773fbe5f379aa7338d56db472581f4b398ef1996e3d00290000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a426f72726f776572203100000000000000000000000000000000000000000000"

Template.hello.onCreated(function helloOnCreated() {
  // counter starts at 0
  this.displayName = new ReactiveVar(0);
});


Template.hello.helpers({
  displayName() {
    var template = Template.instance();

    myContract = web3.eth.contract(ABIArray).at(contractAddress);

    myContract.borrowerName(function(err, res){
        TemplateVar.set(template, "displayName", res)
    });
  },
});

but if I replace borrowerName the variable with getName the function, it fails. The HTML code is as follows:

<template name="hello">
  <button>Click Me</button>
  <p>Borrower Name {{displayName}} {{TemplateVar.get "displayName"}} </p>
</template>

I assume it is something simple I am missing but I would appreciate any help Thanks.

1

So I solved it. Quite simple actually once I figured it out... I simply needed to change the Java Script helper code as follows:

Template.hello.helpers({
  displayName() {
    var template = Template.instance();

    myContract = web3.eth.contract(ABIArray).at(contractAddress);

    myContract.getName(function(err, res){
        TemplateVar.set(template, "getName", res)
    });
  },
});

and the HTML code as follows:

<template name="hello">
  <button>Click Me</button>
  <p>The name of the borrower is {{displayName}} {{TemplateVar.get "getName"}} </p>
</template>

The problem was with the get and set functions. I needed to reference the function getName.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.