I built an ERC20 token with smart contract. It's AZ Token. I have a problem with building transaction from the account that has the total supply to another account Here is the source code and below, i mentioned what i get as a response Please note that i removed the real private key
import json
from web3 import Web3
from solcx import compile_standard, install_solc
import os
import web3
import os
from eth_account import Account
from eth_account.signers.local import LocalAccount
from web3.auto import w3
from web3.middleware import construct_sign_and_send_raw_middleware
with open("./Token.sol", "r") as file:
simple_storage_file = file.read()
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"Token.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
}
},
},
solc_version="0.5.0",
)
ABI = compiled_sol["contracts"]["Token.sol"]["AZ"]["abi"]
w3 = Web3(Web3.HTTPProvider('https://eth-rinkeby.alchemyapi.io/v2/s1IuFuwxKv-xgoGblVYDNVmbegeiqCLB'))
unicorns = w3.eth.contract(address="0x5c5ABbfEdC882D7D863F9EF41d5CF6FF928aCf66", abi=ABI)
nonce = w3.eth.get_transaction_count('0xF56A9A5c8fcBC092b8881e9f34B5ea0e6881C865')
unicorn_txn = unicorns.functions.transfer(
'0x0cfb925C00a4CEF8a22a9F72BC27cCDF074E542C',
900000000000000000000,
).buildTransaction({
'chainId': 4,
'gas': 70000,
'maxFeePerGas': w3.toWei('90', 'gwei'),
'maxPriorityFeePerGas': w3.toWei('90', 'gwei'),
'nonce': nonce+1,
})
private_key = '0x241234123512341234'
signed_txn = w3.eth.account.sign_transaction(unicorn_txn, private_key=private_key)
tx_greeting_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
This is the source code of the contract:
/**
*Submitted for verification at Etherscan.io on 2022-06-23
*/
pragma solidity ^0.5.0;
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
//
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Safe Math Library
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0);
c = a / b;
}
}
contract AZ is ERC20Interface, SafeMath {
string public name;
string public symbol;
uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it
uint256 public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor() public {
name = "AZ Token";
symbol = "AZ";
decimals = 18;
_totalSupply = 100000000 *(10**18);
balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function totalSupply() public view returns (uint) {
return _totalSupply - balances[address(0)];
}
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
}