When using OpenZeppelin SDK how can you use `truffle console`?

Hi @nicob927

Welcome to the community :wave:

With the OpenZeppelin SDK I just use send-tx and call.
Is there something that you can only do in truffle console?

I don’t know if there is a better way, but if you need truffle with an openzeppelin project, then install truffle and init truffle first and then install OpenZeppelin SDK and init OpenZeppelin. This will create a truffle-config.js file that OpenZeppelin SDK will also use (rather than an OpenZeppelin SDK network.js file).

npm init -y
npm install truffle
npx truffle init
npm install @openzeppelin/cli
npx openzeppelin init

You can then setup the network configuration in truffle-config.js (similar to the guide Deploy to a public testnet using OpenZeppelin SDK).

You can deploy your contract using npx openzeppelin create.

$ npx openzeppelin create
âś“ Compiling contracts with Truffle, using settings from truffle.js file
Truffle output:

Compiling your contracts...
===========================
> Compiling ./contracts/Counter.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /mnt/c/Users/andre/Documents/projects/forum/console/build/contracts
> Compiled successfully using:
   - solc: 0.5.8+commit.23d335f2.Emscripten.clang


? Pick a contract to instantiate Counter
? Pick a network development
âś“ Added contract Counter
âś“ Contract Counter deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? No
âś“ Setting everything up to create contract instances
âś“ Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
0xCfEB869F69431e42cdB54A4F4f105C19C080A601

You can then use truffle console to interact with the contract.

$ npx truffle console
truffle(development)> counter = await Counter.deployed()
truffle(development)> counter.increase()
truffle(development)> (await counter.value()).toString()
'1'

You can also use OpenZeppelin SDK interactive commands openzeppelin send-tx and openzeppelin call to interact with the contract.

$ npx openzeppelin send-tx
? Pick a network development
? Pick an instance Counter at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function increase()
âś“ Transaction successful. Transaction hash: 0x08e66950a600f600e5a9134339c2d59885463756fc08264c43c963f788413787
$ npx openzeppelin call
? Pick a network development
? Pick an instance Counter at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function value()
âś“ Method 'value()' returned: 2
2

I have moved the question into it’s own topic so that it is easier for the community to find.