I deployed a smart contract to an azure proof of authority network(ethereum). Following the instructions here https://docs.microsoft.com/en-us/azure/blockchain/templates/ethereum-poa-deployment#tutorials, I was also able to send a signed transaction to the contract which i believe succeeds since i get back a transaction hash. But I cannot successfully query state in the contract. Im not sure what I’m missing or doing wrong. But here’s sample code to describe better.
contract MyContract {
struct Account {
address owner;
boolean active;
}
mapping( address => Account) allAccounts;
function AddAccount(address newAddress) public returns (bool success ) {
allAccounts[newAddress].owner = newAddress;
allAccounts[newAddress].active = true;
return true;
}
function GetAccount(address _address) public view returns( address owner, boolean active) {
return (allAccounts[_address].owner, allAccounts[_address].active);
}
}
I executed the AddAccount method.above by sending a signed transaction as follows
web3.eth.getTransactionCount(accountAddress, (err, nonce) => {
const data = MyContract.methods.AddAccount(
newAddress ).encodeABI();
const rawTx = {
nonce,
gasPrice: '0x00',
gasLimit: '0x2FAF080',
to: contractAddress,
value: '0x00',
data,
};
const tx = new ethereumjs(rawTx);
tx.sign(privateKey);
// var serializedTx = tx.serialize();
const raw = '0x' + tx.serialize().toString('hex');
web3.eth.sendSignedTransaction(raw, (txErr, transactionHash) => {
console.log("TX Hash: " + transactionHash);
console.log("Error: " + txErr);})
Then I try to query the account like so
MyContract.methods.GetAccount(newAddress).call({
from: accountAddress,
}, (error, result) => {
if (error) {
logger.error(`${errors}`);
}
logger.info(`${result}`);
});
However the result of this query always returns wrong values. Like im not able to get the initial values I sent in the first call. Pls what im I doing wrong or how can I make this work?
chainId
value for the rawTx?Exception has occurred: Error Error: Transaction was not mined within750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!