Geth version: Version: 1.9.9-unstable
OS & Version: WSL2 -- Linux 4.19.84-microsoft-standard #1 SMP x86_64 GNU/Linux, Debian, Debian GNU/Linux 9.11 (stretch)
Commit hash : c2d65d34d5c6f27b8d1a52280964023a3eefd66e
decimals method call on ERC20 contract should return 1. totalSupply should return 1000000 (1m).
All method calls return 0/nil.
method calls made in geth terminal:
var contractObject = web3.eth.contract([{"inputs":[{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"string","name":"_tokenSymbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_initialSupply","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"ApprovalEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_admin","type":"address"},{"indexed":true,"internalType":"uint256","name":"_totalSupply","type":"uint256"},{"indexed":false,"internalType":"string","name":"_name","type":"string"}],"name":"Deployed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferEvent","type":"event"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"_tokenOwner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]);
var submittedContract = contractObject.new('DKK', 'DKK', 1, 1000000, {from:web3.eth.accounts[0], data:'0x60806040523480156200001157600080fd5b50604051620010a8380380620010a8833981810160405260808110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b838201915060208201858111156200006f57600080fd5b82518660018202830111640100000000821117156200008d57600080fd5b8083526020830192505050908051906020019080838360005b83811015620000c3578082015181840152602081019050620000a6565b50505050905090810190601f168015620000f15780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200011557600080fd5b838201915060208201858111156200012c57600080fd5b82518660018202830111640100000000821117156200014a57600080fd5b8083526020830192505050908051906020019080838360005b838110156200018057808201518184015260208101905062000163565b50505050905090810190601f168015620001ae5780820380516001836020036101000a031916815260200191505b5060405260200180519060200190929190805190602001909291905050508360029080519060200190620001e492919062000369565b508260039080519060200190620001fd92919062000369565b5081600460146101000a81548160ff021916908360ff1602179055508060058190555033600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506005546000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506005543373ffffffffffffffffffffffffffffffffffffffff167ff0bbe877a87290e236ea898bbce0d78d6ac7d54d62e32744b129798a2669e39b866040518080602001828103825283818151815260200191508051906020019080838360005b838110156200032457808201518184015260208101905062000307565b50505050905090810190601f168015620003525780820380516001836020036101000a031916815260200191505b509250505060405180910390a35050505062000418565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620003ac57805160ff1916838001178555620003dd565b82800160010185558215620003dd579182015b82811115620003dc578251825591602001919060010190620003bf565b5b509050620003ec9190620003f0565b5090565b6200041591905b8082111562000411576000816000905550600101620003f7565b5090565b90565b610c8080620004286000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c806370a082311161006657806370a082311461025457806395d89b41146102ac578063a9059cbb1461032f578063dd62ed3e14610395578063f851a4401461040d5761009e565b806306fdde03146100a3578063095ea7b31461012657806318160ddd1461018c57806323b872dd146101aa578063313ce56714610230575b600080fd5b6100ab610457565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100eb5780820151818401526020810190506100d0565b50505050905090810190601f1680156101185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101726004803603604081101561013c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104f5565b604051808215151515815260200191505060405180910390f35b6101946105e7565b6040518082815260200191505060405180910390f35b610216600480360360608110156101c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105f1565b604051808215151515815260200191505060405180910390f35b6102386108ed565b604051808260ff1660ff16815260200191505060405180910390f35b6102966004803603602081101561026a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610900565b6040518082815260200191505060405180910390f35b6102b4610918565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102f45780820151818401526020810190506102d9565b50505050905090810190601f1680156103215780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61037b6004803603604081101561034557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109b6565b604051808215151515815260200191505060405180910390f35b6103f7600480360360408110156103ab57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b9e565b6040518082815260200191505060405180910390f35b610415610c25565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104ed5780601f106104c2576101008083540402835291602001916104ed565b820191906000526020600020905b8154815290600101906020018083116104d057829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f08245b82180b1f5e514e503c113ab0197093b2cb542145037c0a31b54b1d998e846040518082815260200191505060405180910390a36001905092915050565b6000600554905090565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561064257600090506108e6565b81600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156106cb57600080fd5b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401101561075a57600090506108e6565b81600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167feaf1c4b3ce0f4f62a2bae7eb3e68225c75f7e6ff4422073b7437b9a78d25f170846040518082815260200191505060405180910390a3600190505b9392505050565b600460149054906101000a900460ff1681565b60006020528060005260406000206000915090505481565b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109ae5780601f10610983576101008083540402835291602001916109ae565b820191906000526020600020905b81548152906001019060200180831161099157829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610a075760009050610b98565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054011015610a965760009050610b98565b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167feaf1c4b3ce0f4f62a2bae7eb3e68225c75f7e6ff4422073b7437b9a78d25f170846040518082815260200191505060405180910390a3600190505b92915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea265627a7a72315820dd745ba689c737ea1fe72b1ed32ad9b6d56af636046eb4aaa4abd047c74fbcf364736f6c634300050d0032', gas: 20000000});
submittedContract.address returns "0x6bb41ff521757dcbc9c439040eda0dba30bc56be".
var co = contractObject.at(submittedContract.address);
co.decimals(); returns 0
eth.getCode(submittedContract.address); returns the correct binary of the deployed contract.
https://ethereum.stackexchange.com/questions/78019/unable-to-call-methods-on-my-deployed-contract/
Souce code of deployed ERC20 contract: https://pastebin.com/1eUPALdb
solidity version: Version: 0.5.13+commit.5b0b510c.Linux.g++
I can confirm this on Arch Linux.
Version: 1.9.9-unstable
Git Commit: c2d65d34d5c6f27b8d1a52280964023a3eefd66e
Git Commit Date: 20191202
go version go1.13.4 linux/amd64
I just try to repro your issue, but it works good for me.
The snippet I used
package test
import (
"fmt"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
)
func TestContract(t *testing.T) {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}, 50000000)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
contractAddr, tx, contract, err := DeployTest(transactOpts, contractBackend, "DKK", "DKK", 1, big.NewInt(1000000))
if err != nil {
t.Fatalf("Failed to deploy contract, err: %v", err)
}
contractBackend.Commit()
fmt.Printf("contract address => %x, tx hash => %x\n", contractAddr, tx.Hash())
d, err := contract.Decimals(nil)
if err != nil {
t.Fatalf("Failed to retrieve decimal, err: %v", err)
}
fmt.Printf("decimal => %d\n", d)
supply, err := contract.TotalSupply(nil)
if err != nil {
t.Fatalf("Failed to retrieve total supply, err: %v", err)
}
fmt.Printf("supply => %d\n", supply)
}
The output
contract address => 76de70d4ef657e3ec7ef833e3c4d745d348de42c, tx hash => e0e81dde92a0709d765d6bf0d4664e411d16b3a4f9281b565df74c0efc68f16a
decimal => 1
supply => 1000000
Something I find weird in your case is the gaslimit you assigned is very large: gas: 20000000
It just exceeds the limitation of a block. You can leave this field empty, geth will automatically calculate.
Could the problem somehow be with web3 and JavaScript? Would it be possible for you to test this out in the Geth JS terminal by just pasting the commands that I mention above into the terminal?
@Sword-Smith Did you wait for the contract to be mined? Did you confirm it was mined? The address is known already during submission but that does not mean the transaction will succeed.
Works fine for me too (geth --dev console)
> submittedContract.address
"0xa7880362204ff8eb9a23c05ecab2c10d042059f3"
> var co = contractObject.at(submittedContract.address);
undefined
> co.decimals()
1
If I used the original gas, I get this however
WARN [12-05|11:37:09.063] Served eth_sendTransaction reqid=10 t=579.75碌s err="exceeds block gas limit"
Error: exceeds block gas limit
at web3.js:3143:20
at web3.js:6347:15
at web3.js:5081:36
at web3.js:3021:24
at <anonymous>:1:25
Yes. The transaction creating the contract is mined, as far as I can see.
submittedContract.address
"0xba1f248e57244d7140b55eb4ccbb90c6d5bdb919"
submittedContract.transactionHash;
"0x898de867e5d82ab330a79d9af74bf7e11bbee1c1a7ea63f9bf40b3c9678052c7"
> eth.getTransactionReceipt(submittedContract.transactionHash);
{
blockHash: "0x4969c9d3c0ef6e14b1087589e7d7e24cc0728ce7dc15b97be476fe7b8a2d4bac",
blockNumber: 160,
contractAddress: "0xba1f248e57244d7140b55eb4ccbb90c6d5bdb919",
cumulativeGasUsed: 1085336,
from: "0xa5d2506eac72b3d099b87cd2bbd75fb517ce3286",
gasUsed: 1085336,
logs: [{
address: "0xba1f248e57244d7140b55eb4ccbb90c6d5bdb919",
blockHash: "0x4969c9d3c0ef6e14b1087589e7d7e24cc0728ce7dc15b97be476fe7b8a2d4bac",
blockNumber: 160,
data: "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003444b4b0000000000000000000000000000000000000000000000000000000000",
logIndex: 0,
removed: false,
topics: ["0xf0bbe877a87290e236ea898bbce0d78d6ac7d54d62e32744b129798a2669e39b", "0x000000000000000000000000a5d2506eac72b3d099b87cd2bbd75fb517ce3286", "0x00000000000000000000000000000000000000000000000000000000000f4240"],
transactionHash: "0x898de867e5d82ab330a79d9af74bf7e11bbee1c1a7ea63f9bf40b3c9678052c7",
transactionIndex: 0
}],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000001000000000000000000000000000080000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000010000000000010000000000000000000000000000000000020000000000000000000000000000000110000000000000400000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
status: "0x1",
to: null,
transactionHash: "0x898de867e5d82ab330a79d9af74bf7e11bbee1c1a7ea63f9bf40b3c9678052c7",
transactionIndex: 0
}
eth.blockNumber;169
var co = contractObject.at(submittedContract.address);
undefined
co.decimals();
0
Geth was started with this command:
geth --cache 512 --ipcpath $ipcpath --networkid 42 --port 30301 --rpc --rpcport 30302 --rpcaddr localhost --rpccorsdomain '*' --rpcapi 'eth,net,web3' --datadir ./.ethereum_testserver_data --jspath ./scripts/ --mine --minerthreads=1 --allow-insecure-unlock console 2>> ./out/error.log
where $ipcpath = "$home/.ethereum/geth.ipc";, my $home = File::HomeDir->my_home();
where the above code is Perl :)
Starting geth with geth --dev console gives the correct result! (decimals = 1) It works this way. So the difference between a working and a non-working solution was in the script launching geth. Do anyone have any insight as to what the problem might have been?
This was my test server genesis configuration:
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0
},
"difficulty": "200",
"gasLimit": "8000000000",
"etherbase": "0x3333333333333333333333333333333333333333",
"alloc": {
"7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
"f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
}
}
You didn't enable Constantinople and Petersburg, which new solidity compilers rely on.