Since you cannot use the addresses available under the accounts to sign, the best way is to create one (or more) address(es) using web3.eth.accounts.wallet.create(x) (where x = number of accounts you want to generate).
Within your truffle test, you can create the wallet in the before(...) hook, and reference the newly created address(es) to some globally scoped variables.
contract("Your Contract", async (accounts) => {
let firstAccount,
secondAccount,
thirdAccount
before(async () => {
await web3.eth.accounts.wallet.create(3) // create 3 accounts
firstAccount = web3.eth.accounts.wallet[0]
secondAccount = web3.eth.accounts.wallet[1]
thirdAccount = web3.eth.accounts.wallet[2]
})
// tests here...
})
Each newly created address will have both property and method attach to them (see web3 docs):
Both give you two ways to sign your message.
via web3.eth.accounts.wallet[...].sign(...)
let signature = web3.eth.accounts.wallet[firstAccount].sign("Message To Sign").signature
or alternatively
let signature = web3.eth.accounts.sign("Message To Sign", firstAccount.privateKey).signature
NB: you can also use object destructuring syntax to extract the signature (from the object returned by both signing methods).
This also make the code shorter and a bit easier to read.
// first method
let { signature } = web3.eth.accounts.wallet[firstAccount].sign("Message To Sign")
// second method
let { signature } = web3.eth.accounts.sign("Message To Sign", firstAccount.privateKey)
testrpc --account="0x0F0F0F0F0F%PRIVATE KEY%,10000000000000000000000%INITIAL BALANCE IN WEI%" --secure -u 0- more info – Greg Jeanmart Apr 04 '18 at 11:06web3.eth.personal.signandweb3.eth.signhere: https://ethereum.stackexchange.com/questions/52584/new-update-i-need-to-run-testrpc-signing-a-message-using-ethereumjs-abi But till now I could not solve this problem. Thank you – Questioner Jul 04 '18 at 14:22