1

This is the error I get.

internal/modules/cjs/loader.js:631 throw new ERR_INVALID_ARG_TYPE('id', 'string', id); ^

TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object at Module.require (internal/modules/cjs/loader.js:631:11) at require (internal/modules/cjs/helpers.js:20:18)

This is the Code:

const Web3 = require('web3');
const contract = require('truffle-contract');
const fs = require('fs');

const Artifacts = require('../build/contracts/Organ.json');

const contract = contract(Artifacts);

var app;
var accounts;
var account;

const web3 = new Web3(new 
Web3.providers.HttpProvider('http://127.0.0.1:8545'));
contract.setProvider(web3.currentProvider);

if (typeof contract.currentProvider.sendAsync !== 'function') {
contract.currentProvider.sendAsync = async () =>
    await contract.currentProvider.send.apply(
        contract.currentProvider,
        arguments
    );
}

contract.deployed();

The issue is with the .deplyed() part, everything run properly before that. Everything works fine in the truffle console.

0

We do this to use our contract

const networkId = '9999';
const jsonPath = path.resolve(__dirname, 'json/MyToken.json');
const MyTokenJson = JSON.parse(fs.readFileSync(jsonPath));
const MyToken = contract(MyTokenJson);
MyToken.setNetwork(networkId);
MyToken.setProvider(provider);  
const myToken = MyToken.deployed();

The networkId is in the JSON file inside the networks section.

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.