I have created 3 node (A, B, C) network in that I have deployed simple ERC20 token smart contract on node A.
function balanceOf(address tokenOwner) public view returns (uint256) {
return balances[tokenOwner];
}
function transfer(address receiver, uint256 numTokens) public returns (bool) {
require(numTokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(numTokens);
balances[receiver] = balances[receiver].add(numTokens);
emit Transfer(msg.sender, receiver, numTokens);
return true;
}
I am communicating with smart contract using web3.
const balance = async (httpProvider) => {
const web3 = new Web3(httpProvider);
const id = await web3.eth.net.getId();
const deployedNetwork = token.networks[id];
const accounts = await web3.eth.getAccounts();
const account = accounts[0];
const contract = new web3.eth.Contract(token.abi, deployedNetwork.address);
return contract.methods.balanceOf(
account
).call({ from: account });
}
const transfer = async ({sender, receiver, amount}) => {
const httpProvider = getHttpProvider(sender);
const web3 = new Web3(httpProvider);
const id = await web3.eth.net.getId();
const deployedNetwork = token.networks[id];
const accounts = await web3.eth.getAccounts();
const senderAccount = accounts[0];
const contract = new web3.eth.Contract(token.abi, deployedNetwork.address);
return contract.methods.transfer(
getAddress(receiver),
amount
).send({ from: senderAccount, gas: 30000000, privateFor: [getPublicKey(receiver)] });
}
when I am transferring token from A to B or A to C everything is fine balanceOf(A), balanceOf(B) and balanceOf(C) are returning correct values.
but when I am transferring from B to c balanceOf(B) is showing the correct value but not balanceOf(C) as if transfer didn't happen for C. but from response I can see transfer was successful so why balance of C was not updated correctly?
"events": {
"Transfer": {
"address": "0x4D3bfd7821E237fFE84209d8E638f9f309865b87",
"blockNumber": 32826,
"transactionHash": "0x9e65454b1fd3e983f25010c324dc3a9633e696e77ac8446189c0dc941d42c7a9",
"transactionIndex": 0,
"blockHash": "0x0937d55d1effd81a150df3094ca2d19230c26a74e6dc7b6c83cec5828f51b1a2",
"logIndex": 0,
"removed": false,
"id": "log_09bea0b7",
"returnValues": {
"0": "0xcA843569e3427144cEad5e4d5999a3D0cCF92B8e",
"1": "0x9186eb3d20Cbd1F5f992a950d808C4495153ABd5",
"2": "1",
"from": "0xcA843569e3427144cEad5e4d5999a3D0cCF92B8e",
"to": "0x9186eb3d20Cbd1F5f992a950d808C4495153ABd5",
"value": "1"
},
"event": "Transfer",
"signature": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"raw": {
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000ca843569e3427144cead5e4d5999a3d0ccf92b8e",
"0x0000000000000000000000009186eb3d20cbd1f5f992a950d808c4495153abd5"
]
}
}
}