Hi @poshdan,
I find it much easier to read migrations using async/await, so I recommend using that.
I created a simple example (based on Example on how to use ERC20 token in another contract)
SimpleToken.sol
// contracts/SimpleToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
*/
contract SimpleToken is Context, ERC20 {
/**
* @dev Constructor that gives _msgSender() all of existing tokens.
*/
constructor () public ERC20("SimpleToken", "SIM") {
_mint(_msgSender(), 10000 * (10 ** uint256(decimals())));
}
}
TokenReceiver.sol
// contracts/TokenReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
contract TokenReceiver {
}
2_deploy.js
// migrations/2_deploy.js
const SimpleToken = artifacts.require('SimpleToken');
const TokenReceiver = artifacts.require('TokenReceiver');
module.exports = async function (deployer) {
await deployer.deploy(SimpleToken);
const token = await SimpleToken.deployed();
await deployer.deploy(TokenReceiver, token.address);
const receiver = await TokenReceiver.deployed();
await token.transfer(receiver.address, "100000000");
};
Truffle Develop
Deploy the contracts using migrations and then check the balance manually
$ npx truffle develop
Truffle Develop started at http://127.0.0.1:9545/
...
truffle(develop)> migrate
Compiling your contracts...
===========================
...
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
...
2_deploy.js
===========
Deploying 'SimpleToken'
-----------------------
...
Deploying 'TokenReceiver'
-------------------------
...
truffle(develop)> token = await SimpleToken.deployed()
undefined
truffle(develop)> receiver = await TokenReceiver.deployed()
undefined
truffle(develop)> (await token.balanceOf(receiver.address)).toString()
'100000000'