eos调用eosjs transfer错误及解决

使用eosjs 16版本转账示例:

使用scatter版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const jungle = {
blockchain:'eos',
// protocol:'https',
// host:'nodes.get-scatter.com',
// port:443,
protocol: 'https',
host: 'jungle2.cryptolions.io',
port: 443,
chainId:'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473'
}
scatter.suggestNetwork(jungle);
var eos = scatter.eos(jungle, Eos, eosOptions);
console.log('eos:', eos);

const transactionOptions = { authorization:[`tianji111222@active`] };
eos.transfer({from: 'tianji111222', to: 'tianji111333', quantity: '1.0000 SYS', memo: ''}, transactionOptions).then(function(data) {
console.log(data);
}).catch(function(err) {
console.log('err:', err)
// console.log(data);
});

不使用scatter版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var eos = new Eos({
chainId: jungle.chainId, // 32 byte (64 char) hex string
keyProvider: ['xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'], // WIF string or array of keys..
httpEndpoint: 'https://jungle2.cryptolions.io',
expireInSeconds: 60,
broadcast: true,
verbose: false, // API activity
sign: true
});

eos.transfer({from: 'tianji111222', to: 'tianji111333', quantity: '1.0000 SYS', memo: ''}, function(err, data) {
console.log('err:', err);
console.log('data:', data);
});

出现同一个错误:

1
err: {"code":500,"message":"Internal Service Error","error":{"code":3050003,"name":"eosio_assert_message_exception","what":"eosio_assert_message assertion failure","details":[{"message":"assertion failure with message: unable to find key","file":"wasm_interface.cpp","line_number":924,"method":"eosio_assert"},{"message":"pending console output: ","file":"apply_context.cpp","line_number":72,"method":"exec_one"}]}}

原因:

核心原因在于转账的参数quantity写错了,不知道是以前的教程的版本问题还是什么原因,以前很多文档上都是这样的:

1
quantity: '1.0000 SYS'

现在,应该写成:

1
quantity: '1.0000 EOS'