I'm trying to transfer tokens like this
const Web3 = require('web3');
const abi = require('human-standard-token-abi');
async function testSend() {
let url = 'http://127.0.0.1:8545';
let contractAddress = '0x6031ab93c5e436dfc6f4db819bf50f67e7b1289d';
let from = '0x76b4514ceb23475be392e1305877a834401bdde8';
let secret = 'secret';
let to = '0xe63fb07be1bbc1d84c7e41554faf5457a1c4327e';
let amount = 5 * 10 ** 18;
let gas = 100000;
let web3 = new Web3(new Web3.providers.HttpProvider(url));
let contract = new web3.eth.Contract(abi, contractAddress);
let gasPrice = await web3.eth.getGasPrice();
await web3.eth.personal.unlockAccount(from, secret, null);
let tx = await contract.methods.transfer(to, `${amount}`).send({from, gas, gasPrice});
console.log(tx);
}
and I'm receiving an error "Invalid params: invalid type: null, expected a block number or 'latest', 'earliest' or 'pending'."
{ jsonrpc: '2.0', id: 0, method: 'eth_gasPrice', params: [] }
{ jsonrpc: '2.0', result: '0x3b9aca00', id: 0 }
md5-d0c8bf143f59fd4721c0088b89ccff66
{ jsonrpc: '2.0',
id: 1,
method: 'personal_unlockAccount',
params:
[ '0x76b4514ceb23475be392e1305877a834401bdde8',
'734873kjn873',
null ] }
md5-6a518bb51b86448b875c61ee3034b77b
{ jsonrpc: '2.0', result: true, id: 1 }
md5-f06863f3355b71b7d66b7a21e5263385
{ jsonrpc: '2.0',
id: 2,
method: 'eth_sendTransaction',
params:
[ { from: '0x76b4514ceb23475be392e1305877a834401bdde8',
gas: '0x186a0',
gasPrice: '0x3b9aca00',
data:
'0xa9059cbb000000000000000000000000e63fb07be1bbc1d84c7e41554faf5457a1c4327e0000000000000000000000000000000000000000000000004563918244f40000',
to: '0x6031ab93c5e436dfc6f4db819bf50f67e7b1289d' } ] }
md5-6a518bb51b86448b875c61ee3034b77b
{ jsonrpc: '2.0',
result:
'0xd1e0cf24bb077418b1836470b2d225c37568b373490b1b2087987c2ec8c06545',
id: 2 }
md5-f61d2f0153e73a98e036ac4c706d1d26
{ jsonrpc: '2.0',
id: 3, 15:40
method: 'eth_getTransactionReceipt',
params:
[ '0xd1e0cf24bb077418b1836470b2d225c37568b373490b1b2087987c2ec8c06545' ] }
md5-6a518bb51b86448b875c61ee3034b77b
{ jsonrpc: '2.0',
result:
{ blockHash: null,
blockNumber: null,
contractAddress: null,
cumulativeGasUsed: '0x96b9',
from: null,
gasUsed: '0x96b9',
logs: [ [Object] ],
logsBloom:
'0x0000000000100000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000800000000000000000000000000000000010000000000000000
0000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000002000000000000000000100000000000000000000000000000000000000000010000000000000000000000000000002000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000002',
root: null,
status: '0x1',
to: null,
transactionHash:
'0xd1e0cf24bb077418b1836470b2d225c37568b373490b1b2087987c2ec8c06545',
transactionIndex: '0x0' },
id: 3 }
md5-0c860c0cbd034894d0473ee570d9a032
{ jsonrpc: '2.0',
id: 4,
method: 'eth_getBlockByNumber',
params: [ null, false ] }
md5-6a518bb51b86448b875c61ee3034b77b
{ jsonrpc: '2.0',
error:
{ code: -32602,
message:
'Invalid params: invalid type: null, expected a block number or \'latest\', \'earliest\' or \'pending\'.' },
id: 4 }
Thanks for opening this issue! As it looks like is partiy not returning a block number in the transaction receipt:
{ jsonrpc: '2.0',
result:
{ blockHash: null,
blockNumber: null,
contractAddress: null,
cumulativeGasUsed: '0x96b9',
from: null,
gasUsed: '0x96b9',
logs: [ [Object] ],
logsBloom:
'0x0000000000100000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000800000000000000000000000000000000010000000000000000
0000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000002000000000000000000100000000000000000000000000000000000000000010000000000000000000000000000002000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000002',
root: null,
status: '0x1',
to: null,
transactionHash:
'0xd1e0cf24bb077418b1836470b2d225c37568b373490b1b2087987c2ec8c06545',
transactionIndex: '0x0' },
id: 3 }
Could you open an issue in the parity repository?
BTW with 1.0.0-beta.36 the source piece of code works well.
Yes, because there isn't a check if a new block got mined if you use the HttpProvider. The fix in the latest version would be to use the WebsocketProvider.
Edit: TransactionObserver
Will the issue be fixed for the HttpProvider?
I've changed the source code with the WebsocketProvider. Now it hangs on the line:
let tx = await contract.methods.transfer(to, `${amount}`).send({from, gas, gasPrice});
@vanzay The HttpProvider issue got already fixed and will be released today.
Did you configure the transaction confirmation workflow as documented in the documentation?
Btw.: Could you ask further question in our gitter channel, on StackOverflow or the community-driven discord server?
In 1.0.0-beta.54 the HttpProvider still doesn't work.
Could you add a GitHub repository or all required code snippets to reproduce it?
Did you also test it with a configured transaction confirmation workflow as described in the documentation?
Also tried this way:
let web3 = new Web3(new Web3.providers.HttpProvider(url), null, {
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 24,
transactionPollingTimeout: 480
});
the same result.
You have to wait for 24 blocks and then the transaction will resolve.
But why do I receive an exception? How to avoid it?
@nivida Why has the issue been closed? It's not resolved yet (see the comment above).
I agree, I'm still getting this issue. The issue shouldn't be closed until there's a satisfactory resolution for it. Please re-open.
I am currently not happy:
and now, when i finally figured all that out:
what is going on @nivida?
Could you reference a GitHub repository? @imbenwolf
hi @nivida please see referenced issues in my comment. here a short summary:
Most helpful comment
I agree, I'm still getting this issue. The issue shouldn't be closed until there's a satisfactory resolution for it. Please re-open.