For testing purposes, we'll use TEST collateral with the contracts deployed on Polygon. If you're testing on a live network, this step isn't necessary.
Copy const collateralABI = require ( './abi/FakeStableCoinABI' );
const collateralContract = new web3 . eth .Contract (collateralABI , config . COLLATERAL_ADDRESS );
Copy async function mintCollateralTokens (amount) {
try {
const mintTx = collateralContract . methods .mint ( process . env . WALLET_ADDRESS , amount);
//Gas Buffers
let gas = await mintTx .estimateGas ({from : account .address});
let gasPrice = await web3 . eth .getGasPrice ();
const gasBigInt = BigInt (gas);
const gasPriceBigInt = BigInt (gasPrice);
const increasedGasPrice = gasPriceBigInt * BigInt ( 120 ) / BigInt ( 100 );
const gasWithBuffer = gasBigInt + (gasBigInt * BigInt ( 20 ) / BigInt ( 100 ));
const data = mintTx .encodeABI ();
const nonce = await web3 . eth .getTransactionCount ( account .address);
const tx = {
from : account .address ,
to : config . COLLATERAL_ADDRESS ,
gas : gasWithBuffer .toString () ,
gasPrice : increasedGasPrice .toString () ,
data ,
nonce ,
};
const signedTx = await web3 . eth . accounts .signTransaction (tx , process . env . WALLET_PRIVATE_KEY );
const receipt = await web3 . eth .sendSignedTransaction ( signedTx .rawTransaction);
console .log ( "Tokens minted successfully. Transaction hash: " , receipt .transactionHash);
} catch (error) {
console .error ( "Error minting tokens: " , error);
}
}