Why does web3.js reject a valid RSK smart contract address? - web3js

I'm trying to interact with smart contracts on the RSK Mainnet, and I'm getting this error...
Provided address "0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e" is invalid,
the capitalization checksum test failed,
or its an indirect IBAN address which can't be converted.
The address is obtained from RSK Explorer itself, so I'm not sure why web3.js has this error.

As per RSKIP-60, RSK network has its own checksum validation following EIP1191.
However, some tools and libraries still don't support EIP-1191.
Most Ethereum tools and libraries support EIP-155 only.
web3.js is one of them, and it checks the checksum expecting an EIP-155 checksum.
Workarounds
(1) Convert the smart contract address to an all-lowercase string:
return new web3.eth.Contract(coinBackAbi, tokenObj.address.toString().toLowerCase());
Note that both EIP-155 and EIP-1191 define that all-lowercase addresses are to be treated as "skip checksum".
(2) Another approach is to use #rsksmart/rsk-utils,
using this to convert the address to use the appropriate checksum:
// Ethereum --> use this for web3.js
toChecksumAddress ("0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e", null)
// RSK Mainnet
toChecksumAddress ("0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e", 30)

Related

Web3 JS Library (& Metamask), Get Token Balance

I want to query the eth balance and all token balances of a public key. So far I managed to load web3 and call the getBalance method.
Now, I want to see the balance for ERC20 tokens which are stored with the same public key? E.g. I want to see the balance of OMG tokens?
So far I found that each token contract address has to be queried:
https://ethereum.stackexchange.com/questions/15372/how-can-i-view-all-the-tokens-and-contracts-associated-with-an-ethereum-address
omgContractAddress = "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
OmgContract = web3.eth.contract(abi)
omgContract = OmgContract.at(omgContractAddress)
someUsersAddress = "0x75087d9faa28d653750f3e4c86e7dcf6aff0a916"
omgContract.balanceOf someUsersAddress, (err, balance)-> #some owner
console.error err
console.info balance.toNumber()
Questions:
1) Do I need the abi of each token? Or can I use a standardized abi for ERC20 tokens as long as I just want to use standardized methods?
2) Where do I find the abi? Or do I need to recompile each contract?
E.g. OMG: https://etherscan.io/token/OmiseGo
I could find the abis of several tokens on https://etherscan.io/address/<token_address>#code so far they have the same method common in their abi. I just copied the method directly into my source code without reading the original abi. E.g.
abi = [{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"}]

How to get next certificate in chain

I want to get parent certificate (or all certificates in chain for that matter) from Windows Certificate Store (assuming I know the location of the end certificate). I need to get each one in order to build my own custom X509_STORE (using OpenSSL).
I think the proper course of action would be:
obtain first certificate using CertFindCertificateInStore (done)
get the certificate chain using CertGetCertificateChain (done)
extract the certificates from chain (?)
for each certificate in chain, convert it using d2i_X509 (done)
or
obtain first certificate using CertFindCertificateInStore (done)
get the parent certificate (if exists) (?)
convert it using d2i_X509, go to 2. (done)
Then create the store.
The question to answer is then - how to get the parent certificate or all certificates in chain using Windows Certificate Store? I'm probably missing some more or less occult function here.
as the CertFindCertificateInStore outputs a chain context, one can access it's members using the beautiful construction:
chainContext->rgpChain[0]->rgpElement[iCertIndex]->pCertContext->pbCertEncoded
where iCertIndex is between 0 (end-certificate) and chainSize -1 (self-signed root certificate).

Change Recipient Address Google Apps Script

Is it possible to change the recipient address when using the reply function in Google Apps Script?
I want to receive an email from a random email account, mark it with a label and when scheduled, run the following code to reply to a desired email address rather than the original sender. The reason I want to reply is to keep it in the same thread. I have tried nearly all variations of the following code and can't get it to work the way I want it to:
thread.reply("This is a message.", {
htmlBody: "This is a message.",
name: "My Name",
recipient: "DESIRED#EMAIL.com",
replyTo: "DESIRED#EMAIL.com",
to: "DESIRED#EMAIL.com"
});
If you're asking to generate a random email address and send a real email from that address... that's not possible.
However... you could set the replyTo optional parameter as a random address - though when users would try to reply to that thread they would get a bounce-back notification that the address could not be reached. However, the original sender (the non-random address) would still be visible in the original message.
If you look at the GmailApp docs (replying)/(sending), you'll notice a few limitations. The sender's address (from) must be a valid Alias, if you're sending mail from MailApp (Google Apps Script).
However, there are plenty of methods in the GmailMessage class such as getFrom() and getReplyTo() that would allow you to get/set the message's from/replyTo parameters and have them be the same value. That way, when you reply to a message you will always be in the same thread.

Target email address validiation

Before the client sends a new email, he/she specifies one or more (To) destination addresses. Is there any way to check the validity of these emails before sending the message ?
Define "validity".
This JavaMail FAQ entry might help.
The InternetAddress class only checks the syntax of the address. The InternetAddress class is not able to determine whether the address actually exists as a legal address. It is not even possible to verify the host name if the application is running behind a firewall or isn't currently connected to the Internet.

net-snmp: how do I register for a new enterprise trap?

I'm working with net-snmp and agentx. I have to register my enterprise OIDs for scalars and tables. For example:
netsnmp_register_read_only_scalar(...); // register my scalars
netsnmp_tdata_register(...); // register my table
Until I make those calls in my agentx code, my OIDs don't show up in snmpd.
My MIB file also has NOTIFICATION-TYPE definitions, such as:
myTrapTest NOTIFICATION-TYPE
STATUS current
DESCRIPTION "A sample trap."
::= { myNotifications 1 }
I took a look at #include <net-snmp/agent/agent_trap.h> but this file seems to be about sending traps, not registering custom ones.
My question: What do I call to register my trap definitions?
Turns out there is no registration required for traps. When I asked on the NET-SNMP mailing list, the answer I received was:
You need to 'register' variables/tables so that the master
agent knows which sub-agent to call/invoke (you versus the other guy)
when a particular OID is get/set, but...
You don't have to 'register' trap definitions, you simply have to
'send' the (correctly composed) notification (agentx-Notify-PDU).
(Source: http://permalink.gmane.org/gmane.network.net-snmp.user/35320 )

Resources