Provided Address is invalid, the capitalization checksum test failed - javascript

I am trying to send a method on a contract using web3. I'm creating an account using the privateKeyToAccount method but when sending the method on the contract I get the following error:
Provided address [object Object] is invalid, the capitalization checksum test failed, or it's an indirect IBAN address which can't be converted.
Am I missing a step? I already created an instance of web3 and the contract interface works. I attached part of the code below. Thanks in advance for the help.
const web3 = new Web3(
new Web3.providers.WebsocketProvider(
'wss://rinkeby.infura.io/ws/v3/<api>'
)
);
const dummyPrivateKey = '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358';
const accounts = web3.eth.accounts.privateKeyToAccount(dummyPrivateKey);
await contract.methods // add username
.addMessage(_username, _message)
.send({ from: accounts });

Petr is right. I missed the part where you are giving the whole object instead of address.
But if you want to checksum an address. You can simply use Web3 utility function web3.utils.toChecksumAddress(address) to convert. More details here

You're passing the account object to the from field. But you need to pass just the address.
Replace the from: accounts to from: accounts.address.
Note: This is how the accounts object looks like:
{
address: '0x29B67BB1cFE4799FDb46B49aD81cD771665E2dF7',
privateKey: '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt]
}

Ensure that the address that you are providing is valid. You can get the address from either online providers like Infura or local setup like Ganache.
If still an issue persists, then try to use the following code.
web3.utils.toChecksumAddress(address)

I also encountered this problem in the project, but in my case, I also used Web3 service and same test network at the same time. Stop another service and back to normal now.

Related

Get the list of all Modules inside the Project on ThirdWeb

I was ultimately trying to get the list of all the modules I created inside my Project over the ThirdWeb.com dashboard and filter out the NFT collections out of it. So I asked on discord and someone told me to use the getAllModulesMetadata() to do so, I did something like this
const sdk = new ThirdwebSDK();
const NftModules = sdk
.getAppModule("<Project Address>")
.getAllModuleMetadata([ModuleType.NFT]);
I also did something like this but getting the same issue.
const sdk = new ThirdwebSDK();
async function getAllModules() {
const NftModules = await sdk
.getAppModule("<Project Address>")
.getAllModuleMetadata([ModuleType.NFT]);
}
getAllModules();
Now it gives this error
Unhandled Runtime Error
Error: call revert exception (method="getAllModulesOfType(uint256)", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0)
Is something wrong? Any help will be appreciated :)
You need to pass in an RPC url or a signer in the ThirdwebSDK() constructor before you can use modules:
An RPC URL (which means the sdk is in read-only mode, you won't be able to change state of things on-chain, only fetch it). You can either use something like alchemy or use a public RPC for that particular chain.
A valid ethers signer (which could be connected from metamask, magiclink, coinbase wallet, etc)
A valid ethers.Wallet object, which can be initialised from a private key
const sdk = new ThirdwebSDK("your_rpc_url_or_signer");
Let me know if you still face any issues!

Add Meta Data To Solana Token with #solana/web3.js

I am trying to create an NFT using web3.js and spl-token.js.
However, i need to add meta data (like the name of the token or other attributes), otherwise it just shows up as "Unknown Token" in my wallet.
This is the relevant part of the code where I am minting the token:
let mint = await splToken.Token.createMint(
connection,
fromWallet,
fromWallet.publicKey,
null,
0,
splToken.TOKEN_PROGRAM_ID
);
Otherwise the code is similar to the answers on this question: I would like to mint a new token on solana. How can I do this using solana-web3.js?
There does not seem to be any documentation whatsoever, except for the structure of the meta data (which I found here: https://docs.phantom.app/integrating/tokens/on-chain-metadata).
If anyone could point me in the right direction with an example or documentation it would be really much appreciated. Thank you!
In order to add metadata to NFT you need to invoke this program spl_token_metadata::instruction::create_metadata_accounts. You can find the documentation here.
PS: The example above is in Rust. To do it in JavaScript is like that:
import { Metaplex, keypairIdentity } from "#metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.use(keypairIdentity(keypair));
const mintNFTResponse = await metaplex.nfts().create({
uri: "https://ffaaqinzhkt4ukhbohixfliubnvpjgyedi3f2iccrq4efh3s.arweave.net/KUAIIbk6p8oo4XHRcq0U__C2r0mwQaNl0gQow4Qp9yk",
maxSupply: 1,
});
Like described here is another exemple.
Create a metadata for an NFT token in Solana is quite complicated. It is because in Solana SPL-token account would not carry the Metadata. Instead, you have to create another account to carry such data. So, I suggest you to use Metaplex's Candy Machine to make your own NFT with Metadata. You may get more information from their github:
https://github.com/metaplex-foundation/metaplex/

Trying to register commands: DiscordAPIError[50001]: Missing Access

Following this; https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script
I'm trying to run node deploy-commands.js to register my commands to a single guild and I'm getting the following error.
C:\Users\\\\hello-world-discord-bot>node deploy-commands.js
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\\\\\hello-world-discord-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\\\\\hello-world-discord-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:99:20)
at async C:\\\\\hello-world-discord-bot\deploy-commands.js:17:3 {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'put',
url: 'https://discord.com/api/v9/applications/877359061669118003/guilds/447125601757691915/commands'
}
I've tried removing the bot and re-permissioning it via the developer web console before re-adding it. I've checked and re-added the token clientId and guildId and I get the same error message every time. I can see it's not getting access but I've no idea where else access would be granted from.
My deploy-commands.js looks like this:
{
"clientId": "123456789012345678",
"guildId": "876543210987654321",
"token": "my-token-goes-here"
}
Have you made sure that the 'applications.commands' scope is checked in the scopes section of the OAuth2 settings for your bot in the discord developer portal?
jh316's answer works with the additional context, for us noobs, that checking that box also requires copying the URL, pasting it in a browser so that you can access the authentication page where you get to choose the Discord server the authorization will apply to...and then click 'Authorize' in order to complete the authorization. Then running the deploy-commands.js script will run successfully.
Although I had checked 'applications.commands' it would still not work for me.
The solution was quite simple,
I had copied the id of a text channel when I should have copied the server's id.
I stumbled into this error, in my case the issue was guildId being a number and not a string.
If some one has the related problem =>
1/ Check your developer Page if the Plugin 'applications.commands' at OAuth2 settings checked!
2/ If still not work, just re-invite the bot and haveit "USE SLASH COMMANDS" Permission!

Meteor.js - Fetch/Get Enrollment token (from Accounts.sendEnrollmentEmail)

I can't figure out how to get the enrollment token from the Accounts.sendEnrollmentEmail function.
I know this function sends a direct mail towards the user which in the end looks something like this:
http://localhost:3000/#/enroll-account/FCXzBbqHInZgBlLaOpu8Iv11jP9DJEG-e1auAHDsh6S
However, I would need to somehow get only to the token part FCXzBbqHInZgBlLaOpu8Iv11jP9DJEG-e1auAHDsh6S as I want to send enrollment mail trough a different service (e.g Postmark)
How to do this?
The Accounts.sendEnrollmentEmail(userId, email) function generates a random token and saves it in the user's services.password.reset.token field.
The code that generates the token is:
var token = Random.secret();
var when = new Date();
var tokenRecord = {
token: token,
email: email,
when: when
};
Meteor.users.update(userId, {$set: {
"services.password.reset": tokenRecord
}});
(You can view the function's source code here).
It then sends an email to the user using the Email package. If you want to use a different service to send the email, you basically have 2 options:
Use the same convention yourself (i.e, create the same record and use your own email service in your own function).
Use the existing function, allow the mail delivery to fail silently and then query the user's document for the token and send the email yourself.
Neither is a particularly good option, but both will work for the time being. I wish they had refactored this part into its own function.
Note that the accounts packages are expected to undergo some changes towards the release of the next Meteor versions.
BTW, this function is very similar to Accounts.sendResetPasswordEmail, which you may also wish to override or create your own version.

Twitter, JavaScript & OAuth: failed to validate oauth signature and token

Im trying to implement OAuth using JavaScript, but when I make my request to http://api.twitter.com/oauth/request_token I am getting the above message in the response ("failed to validate oauth signature and token").
As far as I can tell I'm including all the correct parameters, both in the encoding of the signature base:
basestring: (consumer key removed for security)
POST&http%3A%2F%2Ftwitter.com%2Foauth%2Frequest_token%26oauth_callback
%3Doob%26oauth_consumer_key
%3D11111111111111111111112222222222222%26oauth_nonce
%3DO3cHsSXrfnzT%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp
%3D1275928008%26oauth_version%3D1.0
consumer secret: (removed for security)
11111111111111111111112222222222222&
Signature:
R3eHMuQ04F37+xPJSIsoo0aMzc8
Post Data: (consumer key removed for security)
oauth_callback=oob&oauth_consumer_key=11111111111111111111112222222222222&oauth_signature_method=HMAC-SHA1&oauth_signature=pjDh8jkp89ThBtzzB9dQmxQfcg&oauth_timestamp=1275928413&oauth_nonce=qyq3Jhn8rtTZ&oauth_version=1.0
And I've checked that the clock is correct on my device as that's the only real result I can find for this problem :( The nonce is unique and generated every time it runs...
Unfortunately I don't know where to look now. I can't spot anything obvious. I've re-written the entire request twice - once using the oauth.js library and once completely manually, but in both cases it fails with the same error!
Any suggestions?
Cheers
Perhaps the same as this question - which links to a discussin on twitter: apparently client side javascript with oob is not allowed!?!?
Your signature looks wrong, it should always end with a =. Here is an example of a valid one: "YEBbMFDYmp6DvZ3qW1aCx8q7kTc=". Your base string looks right, so I think you've made a mistake with your signature key.
In C#, here is how I built my signature key,
string signatureKey = Uri.EscapeDataString( consumer_secret ) + "&";
var hmacsha1 = new HMACSHA1( new ASCIIEncoding().GetBytes(signatureKey));
string signatureString = Convert.ToBase64String(
hmacsha1.ComputeHash(
new ASCIIEncoding().GetBytes( signatureBaseString ) ) );
string oauth_signature = signatureString;
More info on this process: https://www.dinochiesa.net/?p=17

Categories