Web3.js不接受动作创建者中的const变量作为“发件人:”地址

时间:2019-04-30 23:08:29

标签: redux ethereum redux-thunk web3 web3js

我试图将props对象(在redux存储中保存的合同地址)传递给动作创建者,并将该props对象用作“发件人:”地址。但是,如果我没有手动传递地址的原始字符串,则会收到“指定的地址不存在”

我已经通过了简单的讲话,并且动作创建者的工作很棒。每当我给它变量时。我得到了错误。

//ACTION CREATOR
export const createOrgAndContract = (id) => async (dispatch, getState) => {
    const account = await getState().web3connect.account;
    console.log(account);
    const createContract = await orgFactory.methods.createOrg(id).send({ from: `${account}` });
    const contractAddress = createContract.events.orgCreated.returnValues.newAddress;
    const response = await localDB.post(`/orgs`, { id, contractAddress });

    dispatch({ type: CREATE_CONTRACT_ADDRESS, payload: response.data });
};

这是我尝试过的另一种方法,输出仍然相同:

//ACTION CREATOR V2
export const createOrgAndContract = (id) => async (dispatch, getState) => {
    const account = await getState().web3connect.account;
    console.log(account);
    const createContract = await orgFactory.methods.createOrg(id).send({ from: account });
    const contractAddress = createContract.events.orgCreated.returnValues.newAddress;
    const response = await localDB.post(`/orgs`, { id, contractAddress });

    dispatch({ type: CREATE_CONTRACT_ADDRESS, payload: response.data });
};

这是redux存储中的web3connect.account对象(如果我仅用此地址替换“ account”,则一切正常):

{
  account: '0xB59EaB6A9C3AAC2dba42491502A0699c7b03A857'
}

这是我得到的错误

index.js:756 Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the default options.

有人知道为什么这个变量不符合web3.js中的“发件人”地址吗?

0 个答案:

没有答案