错误提示:

错误提示1

发起合约转账时候提示错误"invalid BigNumber value (argument=\"value\", value=\"1000000000000000000\", code=INVALID_ARGUMENT, version=bignumber/5.5.0)"

错误提示2

invalid BigNumber string (argument="value", value="23222220.111119", code=INVALID_ARGUMENT, version=bignumber/5.3.0

错误原因
该类错误一般是由常用的以太系转币合约中发起合约转账的时候产生,一般引起原因是因为转帐的value值类型引起。
解决方式

错误一如下代码

//转erc20代币
async transferUsdt(amount, from, to) {
var web3 = utils_web3.getWeb3();
let contract = await this.getAssetContract(); //获取web3.eth.Contract合约对像
if (contract.error) return contract
try {
let usdtPrice = amount*Math.pow(10,18); //错误代码
let gasPrice = await web3.eth.getGasPrice();
return await contract.transfer(to, usdtPrice, { gasPrice:gasPrice,from: from});
} catch (e) {
return { error: e.message}
}
}

该类型应该字符串类型,这里为数值类型,所以应该转字符串

//转erc20代币
async transferUsdt(amount, from, to) {
var web3 = utils_web3.getWeb3();
let contract = await this.getAssetContract(); //获取web3.eth.Contract合约对像
if (contract.error) return contract
try {
let usdtPrice = amount*Math.pow(10,18)+""; //转字符串类型
let gasPrice = await web3.eth.getGasPrice();
return await contract.transfer(to, usdtPrice, {gasPrice:gasPrice,from: from});
} catch (e) {
return {error: e.message}
}
}

错误二如下:

//转erc20代币
async transferUsdt(amount, from, to) {
var web3 = utils_web3.getWeb3();
let contract = await this.getAssetContract(); //获取web3.eth.Contract合约对像
if (contract.error) return contract
try {
let usdtPrice = "23222220.111119"; //错误代码
let gasPrice = await web3.eth.getGasPrice();
return await contract.transfer(to, usdtPrice, { gasPrice:gasPrice,from: from});
} catch (e) {
return { error: e.message}
}
}

这里的usdtPrice的值不能为,在合约交互里价值得单位通常是wei,wei是不可分割的最小单位,1eth = 10*18 wei

//转erc20代币
async transferUsdt(amount, from, to) {
var web3 = utils_web3.getWeb3();
let contract = await this.getAssetContract(); //获取web3.eth.Contract合约对像
if (contract.error) return contract
try {
let usdtPrice = 23222220+""; //对应的数值必须为整型
let gasPrice = await web3.eth.getGasPrice();
return await contract.transfer(to, usdtPrice, { gasPrice:gasPrice,from: from});
} catch (e) {
return { error: e.message}
}
}