trufflesuite / truffle-hdwallet-provider

HD Wallet-enabled Web3 provider
MIT License
400 stars 167 forks source link

Contract methods error upon send: address.replace not a function #58

Closed CryptoKiddies closed 6 years ago

CryptoKiddies commented 6 years ago

Version 0.0.6 of hd wallet provider is still buggy I believe. I have tried to send a contract method transaction using Web3 v1 and receive this error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: address.replace is not a function

Code in part is below:


const Web3 = require('web3');
const HDWalletProvider = require('truffle-hdwallet-provider');
const myAbi = require('./abis/transfer');
const BN = Web3.utils.BN;

const provider = new HDWalletProvider(
    '!@#$%^&*()',
    'https://mainnet.infura.io/0987654321'
    , 0, 10);

const web3 = new Web3(provider)

const contractAddress = '0xaaaaaaaaaaaaabbbbbbbbbbbbbbbbaaaaaa'
const myContract = new web3.eth.Contract(myAbi, contractAddress)

// ********************* some code in between - getAccounts etc
// this line works - contract instance fine
const tokenBalance = await myContract.methods.balanceOf(accounts[0]).call()  

// this line breaks
await myContract.methods.transfer(myOtherAccount, tokenBalance)
                .send({ from: accounts[0], gasPrice: newGasPrice })

The txn never reaches the pool. I am not sure if this is still tied to module incompatibility. Perhaps a problem with SolidityTypeAddress or somehow overwriting a common JS method, but very strange. Help would be appreciated!