I'd appreciate help. I'm using ethers.js, creating a signer using a specified private key (which belongs to an account used to deploy an ERC20 contract), registering that address with the Wallet Extension, and then sending a transfer() transaction via the WE. I'm expecting the transfer() to succeed, since the ERC20 owner has a substantial balance.
import ethers from 'ethers';
import fetch from 'node-fetch';
const USER_ADDRESS = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8';
const OBSCURO_HTTP_ENDPOINT = 'http://127.0.0.1:3000';
const PATH_GENERATE_VK = '/generateviewingkey/';
const PATH_SUBMIT_VK = '/submitviewingkey/';
const JSON_HEADERS = { 'Accept': 'application/json', 'Content-Type': 'application/json' };
const ERC20_ADDRESS = '0x9802F661d17c65527D7ABB59DAAD5439cb125a67';
const ERC20_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
const rpcProvider = new ethers.providers.JsonRpcProvider(OBSCURO_HTTP_ENDPOINT);
const erc20Issuer = new ethers.Wallet(ERC20_PRIVATE_KEY, rpcProvider);
const ERC20_ISSUER_ADDRESS = erc20Issuer.address;
const ERC20_ABI = [
{
"inputs": [
{ "internalType": "address", "name": "receiver", "type": "address" },
{ "internalType": "uint256", "name": "numTokens", "type": "uint256" }
],
"name": "transfer",
"outputs": [
{ "internalType": "bool", "name": "", "type": "bool" }
],
"stateMutability": "nonpayable",
"type": "function"
}
];
const erc20 = new ethers.Contract(ERC20_ADDRESS, ERC20_ABI, rpcProvider);
(async () => {
const generateViewingKeyResp = await fetch(
OBSCURO_HTTP_ENDPOINT + PATH_GENERATE_VK, {
method: 'POST',
headers: JSON_HEADERS,
body: JSON.stringify({ 'address': ERC20_ISSUER_ADDRESS })
}
);
if (!generateViewingKeyResp.ok) {
alert('Failed to generate viewing key for Issuer.' + generateViewingKeyResp);
return;
};
const viewingKey = await generateViewingKeyResp.text();
console.log(viewingKey);
const signature = await erc20Issuer.signMessage(JSON.stringify(['vk' + viewingKey, erc20Issuer.address]));
const signedViewingKeyJson = { "signature": signature, "address": erc20Issuer.address }
const submitViewingKeyResp = await fetch(
OBSCURO_HTTP_ENDPOINT + PATH_SUBMIT_VK, {
method: 'POST',
headers: JSON_HEADERS,
body: JSON.stringify(signedViewingKeyJson)
}
);
if (!submitViewingKeyResp.ok) {
console.log('Failed to submit viewing key for Issuer.' + submitViewingKeyResp.statusText);
return;
};
const tx = await erc20.populateTransaction.transfer(
USER_ADDRESS,
ethers.utils.parseUnits('1.0', 18),
{ gasLimit: 400000 }
);
const sentTx = await erc20Issuer.sendTransaction(tx);
const receipt = await sentTx.wait();
alert('Request accepted. Your receipt is: ' + JSON.stringify(receipt));
})().catch(err => {
console.error(err);
});```
I'd appreciate help. I'm using ethers.js, creating a signer using a specified private key (which belongs to an account used to deploy an ERC20 contract), registering that address with the Wallet Extension, and then sending a transfer() transaction via the WE. I'm expecting the transfer() to succeed, since the ERC20 owner has a substantial balance.
Here's a minimal set of code to reproduce the issue: