Open damianlluch opened 3 years ago
Another thing I'm trying to do with your contract, is a script to transfer tokens.
This is my approach.
// src/index.js
const Web3 = require('web3');
const { setupLoader } = require('@openzeppelin/contract-loader');
require('dotenv').config();
async function main() {
// Set up web3 object
const web3 = new Web3(new Web3.providers.HttpProvider(
'https://ropsten.infura.io/v3/4e8d6450a0b140928f887c0adf076d9c'
));
const loader = setupLoader({ provider: web3 }).web3;
// Set up a web3 contract, representing a deployed ERC20, using the contract loader
const address = '0x960b4F3bbB08F595Fa8F222330cC4B38822513fC';
const token = loader.fromArtifact('WoonklyERC20', address);
// Retrieve accounts
const myAccount = web3.eth.accounts.privateKeyToAccount(process.env["MNEMONIC_PRIVATEKEY_TESNET"]);
const otherAccount = web3.eth.accounts.privateKeyToAccount(process.env["OTHER_PRIVATE_KET_TESTNET"]);
// Call the deployed token contract
const name = await token.methods.name().call();
const symbol = await token.methods.symbol().call();
const decimals = await token.methods.decimals().call();
const totalSupply = await token.methods.totalSupply().call();
console.log(`${name} (${symbol}) - Decimals:${decimals} Total Supply:${totalSupply}`);
try {
const tokenBalance = await token.methods.balanceOf(otherAccount.address).call();
const tx = await token.methods
.addBalanceToUser(otherAccount.address, 1000000 ).send({ from: myAccount.address }) // the contract function
const tokenBalanceee = await token.methods.balanceOf(otherAccount.address).call();
console.log(tx)
console.log(tokenBalanceee)
}
catch(err) {
console.log(err)
}
// At termination, `provider.engine.stop()' should be called to finish the process elegantly.
}
main();
And the addBalanceToUser function, return me this error
damian@damian-Latitude-7400:~/Documents/work/wonklyerc20$ node scripts/index.js Uniswap (UNI) - Decimals:18 Total Supply:0 { Error: Returned error: The method eth_sendTransaction does not exist/is not available
Hello Damian,
The first error comes from the web. This project lets you create accounts for users and between them they can transfer tokens, this check is done from the web. I plan to implement it as an improvement, adding the implementation with metamask.
Hi, I have tried to test your project. I made the migrations as normal in Ganache, but in the frontend I got this error. I am running the frontend with ganache account 0, which has balance....
any suggestions?
Regards
The requested amount to trasnfer is bigger than the user owns