I deployed my contract at 0xa518a732606baae1c72490313cb7bb42c62c7a50. Now, what I try to do is to interact with my functions.. I've created an node.js application over web3 and truffle/contract but I can't access my smart contract(it is named Diploma). My error: UnhandledPromiseRejectionWarning: Error: Cannot create instance of Diploma; no code at address 0xa518a732606baae1c72490313cb7bb42c62c7a50

Also, I made this post for asking more things I don't know if I understand good..

This is what I tried:

const express = require("express");
const app = express();
const Web3 = require("web3");
const contract = require("@truffle/contract");
const artifact = require("./build/contracts/Diploma.json");


if (typeof web3 !== "undefined") {
  var web3 = new Web3(web3.currentProvider);
} else {
  var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));

// when I npm start my default provider is taken as Ganache. I suppose it's normal since my node
// can't see my Metamask, right?

const Diploma = contract(artifact);

app.listen(8082, async () => {
  const accounts = await web3.eth.getAccounts(); // if I console.log this, all my 10 ganache 
                                                 // accounts are shown 
  const balance = await web3.eth.getBalance(accounts[0], function(err, result) {
    console.log('result', result);

  var contract_address = "0xa518A732606baae1C72490313Cb7bB42c62c7a50";
  Diploma.at(contract_address).then(function (instance) { // here is where I get the error


Also, I have one more question. If I make transactions which I want to persist on Ropsten using my smart contract methods, can I choose the transaction hash / address where my data to be stocked or something like this? And after to retrieve them from that address?

Let's say this are my method:

function method(bytes32 _checksum, uint _data) public {

        myMapping[_checksum].isSet = true;
        myMapping[_checksum].timestamp = block.timestamp;
        myMapping[_checksum].data = _data;
        myMapping[_checksum].setBy = msg.sender;
        some Event for logs

function getDiploma(bytes32 _checksum) public view returns(uint, address) {
        return (myMapping[_checksum].data, myMapping[_checksum].setBy);

I suppose it's pretty obvious what I try to make. If this is not an optimum method can you give my an advice of how can I implement something to work how I want to..? If this is possible.

I've already saw this post and this post and more others..


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.