blockchain tutorial Error: The send transactions "from" field must be defined - ethereum

I am following a blockchain tutorial from dappuniversity.
When I create the task in the line
await App.todoList.createTask(content)
from line
https://github.com/dappuniversity/eth-todo-list/blob/e3ed9a2cefb581c09730250c56c9d30a19cc63c8/src/app.js#L115
I get the following error :
Uncaught (in promise) Error: The send transactions "from" field must be defined!
at Method.inputTransactionFormatter (truffle-contract.js:50747)
at truffle-contract.js:51228
at Array.map (<anonymous>)
at Method.formatInput (truffle-contract.js:51226)
at Method.toPayload (truffle-contract.js:51261)
at Eth.send [as sendTransaction] (truffle-contract.js:51551)
Do I need to define a 'from' field somewhere?

With the latest dependencies, none of the above answers were working for me.
I had to edit the loadAccount method:
loadAccount: async () => {
// Set the current blockchain account
const accounts = await web3.eth.getAccounts();
App.account = accounts[0];
},
then pass the App's account to the createTask method: await App.todoList.createTask(content, { from: App.account })

I was running into issues with the above answer which appears due to recent Metamask updates and that moving from web3.currentProvider to window.ethereum
I was able to make this work using
await App.todoList.createTask(content, {from: App.account})

I am using the latest truffle/contract. I needed to specify the from account in my createTask method like the following:
await App.todoList.createTask(content, { from: web3.eth.defaultAccount})
This worked.

Same happened to me on Remix while interacting with the contract deployed on Rinkeby. I chose injected web3 for the environment, But account field was empty.
It happended because I rejected the connection to metamask first and then did not get any other request to connect with metamask. So I refreshed remix, locked and unlocked metamask. It sent request to connect to metamask

Related

Caught exception: TypeError: listener is not a function while publish redis client using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0",

When using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0"
getting such exeption below:
Caught exception: TypeError: listener is not a function Exception
origin: uncaughtException[2022-07-18T07:39:30.386Z] process.on
uncaughtException ERRORCODE 105199 TypeError: listener is not a
function
at Function._RedisCommandsQueue_emitPubSubMessage (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/#redis/client/dist/lib/client/commands-queue.js:241:9)
at RedisCommandsQueue._RedisCommandsQueue_handlePubSubReply (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/#redis/client/dist/lib/client/commands-queue.js:283:100)
It's working fine while using node redis "redis": "^2.8.0".
I had a similar issue where I was using probably some old way of subscribing and receiving the messages. Something like this:
sub.on('message', (channel, message) => {
redisClient.hSet('values', message, someFunction);
});
sub.subscribe('channel');
I hope you are using the right way of publishing and subscribing to a channel in redis client. Here is one example from their documentation:
// This is how you create the client
import { createClient } from 'redis';
const client = createClient();
// This is the subscriber part
const subscriber = client.duplicate();
await subscriber.connect();
await subscriber.subscribe('channel', (message) => {
console.log(message); // 'message'
});
// This is an example of how to publish a message to the same channel
await publisher.publish('channel', 'message');
Here is the link if you would like to see some more details about publishing and subscribing of the messages using node-redis client: https://github.com/redis/node-redis#pubsub

CredentialsError: Could not load credentials from ChainableTemporaryCredentials in AWS-SDK v2 for Javascript

I am trying to set up temporary credentials in the AWS-SDK v2 for Javascript:
const aws = require('aws-sdk')
aws.config = new aws.Config({
credentials: new aws.ChainableTemporaryCredentials({
params: {
RoleArn: roleArn, // Defined earlier
RoleSessionName: sessionName, // Defined earlier
DurationSeconds: 15 * 60
},
masterCredentials: new aws.Credentials({
accessKeyId: accessKeyId, // Defined earlier
secretAccessKey: awsSecretAccessKey // Defined earlier
})
}),
region: 'us-east-1',
signatureVersion: 'v4'
})
aws.config.getCredentials(function (err) {
if (err) console.log(err.stack)
else console.log('Access key:', aws.config.credentials.accessKeyId)
})
However, I'm keep getting the following error, which occurs when calling getCredentials:
CredentialsError: Could not load credentials from ChainableTemporaryCredentials
Note that it works fine if I set the credentials parameter to the master credentials instead of the temporary credentials, as shown below:
aws.config = new aws.Config({
credentials: new aws.Credentials({
accessKeyId: accessKeyId, // Defined earlier
secretAccessKey: awsSecretAccessKey // Defined earlier
}),
region: 'us-east-1',
signatureVersion: 'v4'
})
Does anyone know what's causing this issue? Here's the documentation I was referencing:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ChainableTemporaryCredentials.html
I was finally able to figure out the cause of this error.
What led me to figure out the cause of the error was when I printed out the full error instead of just the most recent error. One of the properties of the error was:
originalError: {
message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.',
code: 'SignatureDoesNotMatch',
time: 2021-12-11T19:49:52.395Z,
requestId: '402e4c32-7989-4287-a6a9-628bfc93f60f',
statusCode: 403,
retryable: false,
retryDelay: 39.60145242362791
}
So I realized the problem was that my masters credentials I provided were not correct!
I have actually always known that these credentials weren't correct, but for unit-testing purposes it seemed to work fine with these incorrect credentials as long as I didn't also supply the temporary credentials. But now I understand that the getCredentials function verifies the credentials with AWS if you're using temporary credentials, but doesn't verify with AWS when using just master credentials. That explains that strange behavior I was seeing.

Default account for Ropsten deployment using truffle-hd-wallet

I'm trying to deploy a custom ERC20 Token to Ropsten network by using truffle-hd-wallet. The transaction was went well, however, the weird thing was the newly deployed custom ERC20 token main holder account it wasn't my desired account but an unknown account. When I added the token to my own Ropsten account the amount is ZERO which supposed to have the initial values. Is there a way I can set my desire deployment contract address to the truffle? Please advise.
Thank you.
Desire Address : 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5
Actual Address : 0xEDD4C3676c8579D25463040fd196626a9B7C60a2
ropsten: {
provider: function() {
return new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/" + INFURA_API_KEY, 0);
},
network_id: 3,
gas: 4700000
}
},
module.exports = function(deployer) {
deployer.deploy(CToken).then(function () {
let walletA = walletAaddr;
let walletB = walletBaddr;
return deployer.deploy(
CTokenSale,
CToken.address,
walletA,
walletB
).then(function () {
// token ownership setting
CToken.deployed().then(function(instance) {
let fptc = instance;
return fptc.transferOwnership(CTokenSale.address, {gas:1000000});
}).then(function(result) {
console.log("transferOwnership successful!")
}).catch(function(e) {
console.log("Ownership Transfer failed!")
});
CToken.deployed().then(function(instance) {
let fptc = instance;
return fptc.transfer(CTokenSale.address, 100, {gas:1000000});
}).then(function(result) {
console.log("Sales Token Ready!")
}).catch(function(e) {
console.log("Sales Token failed to deploy!")
});
});
});
};
You haven't included your token smart contract code. I assume that the account deploying the tokens either is given the initial supply, or has a minter role.
I suggest you confirm that the first account derived from your 12 word seed phrase (mnemonic) is the address that you want: e.g. 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5.
You are specifying the first account with 0 as the address_index.
With Truffle HDWallet Provider you can specify a derivation path if you are using something different from the default.
https://github.com/trufflesuite/truffle/tree/develop/packages/truffle-hdwallet-provider
I recommend reading the OpenZeppelin documentation (if you haven't already) on:
Tokens: https://docs.openzeppelin.org/v2.3.0/tokens
Crowdsales: https://docs.openzeppelin.org/v2.3.0/crowdsales
You can also ask questions at:
Ethereum Stack Exchange: https://ethereum.stackexchange.com/
Zeppelin Community Forum: https://forum.zeppelin.solutions/

web3.eth.accounts.create method doesn't actually create new account

I try to create an eth account via RPC in private network.
What I have done so far are:
launch geth node and create private network.
create simple javascript program using web3 1.0.0, typescript
run and get result as below but the account isn't created
Code:
const result = await web3.eth.personal.unlockAccount(senderId, senderPassword, duration)
if (result === true) {
// const newAccountResult = await web3.eth.personal.newAccount('password')
const newAccountResult = await web3.eth.accounts.create('user01')
console.log(newAccountResult)
}
Result:
web3.eth.accounts.create returns the following result
{ address: '0xf10105f862C1cB10550F4EeB38697308c7A290Fc',
privateKey: '0x5cba6b397fc8a96d006988388553ec17a000f7da9783d906979a2e1c482e7fcb',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt] }
But web3.eth.getAccounts method returns only 1 account.
[ '0xaf0034c41928Db81E570061c58c249f61CFF57f2' ]
Seems web3.eth.accounts.create method has succeeded as the result includes account address and private key.
But I don't understand why web3.eth.getAccounts method doesn't include the created account.
I also checked geth via console, the result is same.
> eth.accounts
["0xaf0034c41928db81e570061c58c249f61cff57f2"]
And eth.personal.newAccount didn't work.
Do I need to do something after web3.eth.accounts.create?
I appreciate any help.
If i got it right, web.eth.accounts.create is a way to create accounts without storing them on the local node, so its basically a way to get a valid keypair on-the-fly without storing anything on the keystore)
web3.eth.personal.newAccount() should be availabel if you have the personal-API activated on your geth node (which is default behavior for ganache, with geth you need to activate it via geth --dev/testnet --rpc --rpcapi eth,web3,personal (note: of course you should be very careful with allowing personal-API on mainnet, make sure that RPC access is restricted so only you/privileged users can access it)
(async () => {
let newAccount = await web3.eth.personal.newAccount();
console.log(newAccount);
let accounts = await web3.eth.getAccounts();
console.log(accounts);
})();
Should give something like
0xb71DCf0191E2B90efCD2638781DE40797895De66
[
...
'0xb71DCf0191E2B90efCD2638781DE40797895De66' ]
Refs https://medium.com/#andthentherewere0/should-i-use-web3-eth-accounts-or-web3-eth-personal-for-account-creation-15eded74d0eb

Cosmos-gui application crashes after authentication with keystone

I have a problem. My cosmos gui application crashes after trying to authorize with keystone.
Horizon application is running on https://192.168.4.33:443,
while cosmos-gui is running on http://192.168.4.180:81.
My gui config file looks like this:
"oauth2": {
"idmURL": "https://192.168.4.33",
"client_id": "***********************************",
"client_secret": "*********************************",
"callbackURL": "http://192.168.4.180:81/auth",
"response_type": "code"
},
and inside horizon i registered application Cosmos Big data
with parameters:
Description
Cosmos Big data
URL
https://192.168.4.33
Callback URL
http://192.168.4.180:81/auth
So afterwards i start cosmos-gui application and after clicking on login it redirects me to this url:
https://192.168.4.33/oauth2/authorize/?response_type=code&client_id=0434fdf60897479588c3c31cfc957b6d&state=xyz&redirect_uri=http://192.168.4.180:81/auth
And that is ok.But then, when i click on button authorize it leads me to this url:
http://192.168.4.180:81/auth?state=xyz&code=NVfyZUov1KuQ8yTw498oItHgYC2l9Z
and at that moment cosmos-gui application crashes and everything that i get from the log is this:
/home/cosmos-gui/fiware-cosmos/cosmos-gui/src/app.js:138
req.session.access_token = results.access_token;
^
TypeError: Cannot read property 'access_token' of undefined
at /home/cosmos-gui/fiware-cosmos/cosmos-gui/src/app.js:138:43
at /home/cosmos-gui/fiware-cosmos/cosmos-gui/src/oauth2.js:168:22
at ClientRequest.<anonymous> (/home/cosmos-gui/fiware-cosmos/cosmos- gui/src/oauth2.js:140:9)
at ClientRequest.emit (events.js:95:17)
at CleartextStream.socketErrorListener (http.js:1548:9)
at CleartextStream.emit (events.js:95:17)
at SecurePair.<anonymous> (tls.js:1400:19)
at SecurePair.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:980:10)
at CleartextStream.read [as _read] (tls.js:472:13)
On the side of keystone everything looks ok.This is from keystones log:
2015-08-24 16:34:02.604 27693 INFO keystone.contrib.oauth2.controllers [-] OAUTH2: Created Authorization Code to consumer 0434fdf60897479588c3c31cfc957b6d for user idm with scope [u'all_info']. Redirecting to http://192.168.4.180:81/auth?state=xyz&code=NVfyZUov1KuQ8yTw498oItHgYC2l9Z
2015-08-24 16:34:02.606 27693 INFO eventlet.wsgi.server [-] 127.0.0.1 - - [24/Aug/2015 16:34:02] "POST /v3/OS-OAUTH2/authorize HTTP/1.1" 302 208 0.121336
When you authorize the Cosmos app in Keystone, the callback URL is called and this piece of software is executed:
// Handles requests from IDM with the access code
app.get('/auth', function(req, res) {
// Using the access code goes again to the IDM to obtain the access_token
oa.getOAuthAccessToken(req.query.code, function (e, results){
// Stores the access_token in a session cookie
req.session.access_token = results.access_token;
res.redirect('/');
});
});
I.e. Keystone calls the callback with an access code (a soft piece of security) that can be used to retrieve the final access token (a hard security element).
It seems your Keystone is generating the access code but it is not returning the access token when asked for it. Can you check the Keystone logs in order to find the access token request? May you print any error returned by this call?
oa.getOAuthAccessToken(req.query.code, function (e, results)
After a bit of debugging and printing arguments that were going into the app.get('/auth', function(req, res)
i found this Error: DEPTH_ZERO_SELF_SIGNED_CERT
It seems it doesn't recognize self signed certificates as valid.
Anyway as first line in file:
cosmos-gui/src/app.js
i added
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
and now it is working.