Solidity-Vertragsstatus wird nicht durch signierte Transaktion in nodejs aktualisiert

Durch signierte Transaktion mit web3 in nodejs

Transaktionshash

0x3c7688326afc83e6524e8c491f203852e34aa0f572d952569b6253e98dbd83a1

Daten

0xf9bcd5450000000000000000000000008d19c274d690f84efd4a443c21c4f4a1b77720ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000

Erhalt

{"receipt":{"blockHash":"0x54f01d72226e3cd75d7b5c6952cac149dab47aabffbf5251d87f86613f223657","blockNumber":549010,"contractAddress":null,"cumulativeGasUsed":23384,"from":"0x0a889e242e6afaaaf51d9e40b2f089ab03889f97","gasUsed":23384,"logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x4a0f79b6b74ce735aebfaa2e19ef066f500a6fa3051922fd193abe4219a158b8","to":"0x32ffcced3e2d7979cf7005fd8a9de681408f70dc","transactionHash":"0x3c7688326afc83e6524e8c491f203852e34aa0f572d952569b6253e98dbd83a1","transactionIndex":0}}

Remix verwenden

Transaktionshash

0x7b7c6006c078abaf10150e685f4bb7b755bf3de2e6baa29105128a7ef4f838f9

Daten

0xf9bcd5450000000000000000000000008d19c274d690f84efd4a443c21c4f4a1b77720ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000

Erhalt

receipt={"receipt":{"blockHash":"0x8e365df7f4d07510b69a9f540cefc39c47ec117e7cfdd5516c15b92abc1d7488","blockNumber":549012,"contractAddress":null,"cumulativeGasUsed":99095,"from":"0x0a889e242e6afaaaf51d9e40b2f089ab03889f97","gasUsed":99095,"logs":[{"address":"0x32fFcceD3e2d7979cf7005Fd8A9DE681408F70Dc","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000a889e242e6afaaaf51d9e40b2f089ab03889f97","0x0000000000000000000000008d19c274d690f84efd4a443c21c4f4a1b77720ed"],"data":"0x000000000000000000000000000000000000000000000000000000000000012c","blockNumber":549012,"transactionHash":"0x7b7c6006c078abaf10150e685f4bb7b755bf3de2e6baa29105128a7ef4f838f9","transactionIndex":0,"blockHash":"0x8e365df7f4d07510b69a9f540cefc39c47ec117e7cfdd5516c15b92abc1d7488","logIndex":0,"removed":false,"id":"log_8e8a9b3e"}],"logsBloom":"0x00000000000000000000000000000000000080000000000000000000000000000000000000000400000000000000002000000000000000000000000000000000000000000000000000000008000000000000000000000000000000200000000000000000000000000000000004000000000000000000000000000010000008000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000","root":"0x156468c1bbde543ecae47841270c2037f4bc284df744e4a1ea7b5171bea1704e","to":"0x32ffcced3e2d7979cf7005fd8a9de681408f70dc","transactionHash":"0x7b7c6006c078abaf10150e685f4bb7b755bf3de2e6baa29105128a7ef4f838f9","transactionIndex":0}}

Solidität (Funktion)

function createUser(address _address, string _name) onlyOwner public {
         User memory newUser;// for temporary data
         newUser.id=_address;
         newUser.name=_name;

         //check if exists
         users[newUser.id]=newUser;
         _totalUser++;

         //Send initial ether to that public key
         balances[_address] = balances[_address].add(NEW_ACCOUNT_TOKEN);
         _totalSupply=_totalSupply.add(NEW_ACCOUNT_TOKEN);

         emit Transfer(owner,_address , _totalSupply);
    }

Nodejs + web3js

const contract = new web3.eth.Contract(abi, process.env.CONTRACT_ADDRESS);
const data = contract.methods.createUser('0x40c6f8cda775e5fc26c3f7782518f146a1fdf746', 'abc').encodeABI();
var privateKey = Buffer.from(process.env.WALLET_PRIVATE_KEY, 'hex');

web3.eth.estimateGas({
    to: process.env.WALLET_ADDRESS,
    data: data
}).then((estimateGas) => {
    log('estimateGas: ' + estimateGas);

    web3.eth.getTransactionCount(process.env.WALLET_ADDRESS).then((nonce) => {
        log('nonce:' + nonce); //
        var rawTx = {
            nonce: nonce,
            from: process.env.WALLET_ADDRESS,
            to: process.env.CONTRACT_ADDRESS,
            gasPrice: web3.utils.toHex(web3.utils.toWei('2', 'gwei')),
            gas: estimateGas,
            data: data
        }

        var ethTx = new EthereumTx(rawTx);
        ethTx.sign(privateKey);

        var serializedTx = ethTx.serialize();

        web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
            .once('transactionHash', function (hash) {
                log('hash: ' + hash)
                res.json({
                    'status': true,
                    'msg': 'Successfully submitted',
                    'data': {
                        'tx': hash
                    }
                });
            })
            .once('receipt', function (receipt) {
                log('receipt for ' + receipt.transactionHash);
            })
            .on('error', function (error) {
                log(error);
            })
            .then(function (receipt) { // will be fired once the receipt is mined
                log(receipt.transactionHash + ' is mined'  );
                log('tx: ' + receipt.transactionHash + ' \n' + 'cumulativeGasUsed  : '  + receipt.cumulativeGasUsed
                    + ', blockNumber: ' + receipt.blockNumber +', blockHash:  '+ receipt.blockHash + ' \nlogs : ' + receipt.logs)
            });
    });
});

Beide sind Transaktionen im selben Vertrag mit demselben privaten Schlüssel. In beiden Fällen sind die Eingabeparameter der Funktion gleich, weshalb die Daten für beide Fälle gleich sind. Aber die Remix-Transaktion aktualisiert den internen Zustand und web3 (unter Verwendung von nodejs) nicht. Und das Transaktionsprotokoll fehlt auch für die Transaktion web3js (nodejs). Die Gesamtzahl der Benutzer ändert sich nicht von web3js+nodejs

Was könnten die möglichen Gründe sein?

Können Sie Ihren Solidity- und JavaScript-Code teilen? Es wird hilfreich sein, um das Problem zu reproduzieren und es besser zu verstehen.
@SohamLawar aktualisiert

Antworten (1)

Nach Erhalt des Quittungsfeldes war das Statusfeld undefiniert , d. h. die Transaktion wurde nicht abgebaut, da zu wenig Gas geliefert wurde. Schließlich wurde das Problem behoben, nachdem standardmäßig genügend Gas bereitgestellt wurde

 var rawTx = {
            nonce: nonce,
            from: process.env.WALLET_ADDRESS,
            to: process.env.CONTRACT_ADDRESS,
            gasPrice: web3.utils.toHex(web3.utils.toWei('2', 'gwei')),
            gas: 1500000,
            data: data
        }