0

I am at the point where I have migrated my smart contract to a local copy of the TestRPC test client.

1) Using a Node.JS app running on the same PC as the TestRPC test client, can I use the deploy() function to deploy a new instance of my smart contract to the locally running TestRPC client? Or is that only possible with a test net like Rinkeby, etc. or the Ethereum main net as the deploy target?

2) Same question but for accessing smart contracts via the Web3.js library. Can I use that library to interact with the smart contract instance running in the local TestRPC client from a Node.js app running on the same pC.

If anyone has any links to any good samples that shows how to migrate/deploy a smart contract and access the smart contract's view functions from a Node.JS app using the Web3.js library, please share.

2

I would look in to the documentation of using the Truffle Framework. It allows you to deploy and interact with your smart contracts on TESTRPC or Rinkeby.

1

To answer your 2nd question, here is an example:

contract("MyContractTest", () => {
    let FACTOR = 5;

    let myContract;
    before(async () => {
        myContract = await artifacts.require("MyContract.sol").new(FACTOR);
    });

    describe(`my test:`, async () => {
        for (let i = 0; i < 100; i++) {
            it(`func(${i})`, async () => {
                try {
                    let expected = i * FACTOR;
                    let actual   = await myContract.func(i);
                    assert(actual.equals(expected), `expected ${expected} but got ${actual}`);
                }
                catch (error) {
                    assert(false, error.message);
                }
            });
        }
    });
});

Everything you need is here.

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.