Convert wallet address on Tron - blockchain

I need to get the wallet address from the trc-20 transaction on the Trone network.
I found out that this info can be taken from the input field. I use web3.js to parse this field and get an address like
0xee564858c4874cac2d1fff98c1eabba915f50b2f
But I need it to be like
TXhRBjb8GDnodu3VY6vgmNXcGnLpQhm9NW
I can't find the info how to convert it

tronWeb.address.toHex :
Convert Base58 format addresses to Hex
const convertedAddress = tronWeb.address.toHex(givenAddress);
tronWeb.address.fromHex :
Convert Hexstring format address to Base58 format address
const convertedAddress = tronWeb.address.fromHex(givenAddress);
tronWeb.address.fromPrivateKey :
Derive its corresponding address based on the private key
const givenAddress = tronWeb.address.fromPrivateKey(privateKey);
source link

Related

How do I parse a String to Time in Crystal Lang?

I have a String in MM-DD-YYYY format such as: 04-08-2022.
I want to parse that to a Time type.
How do I do that in Crystal?
Crystal has a Time.parse (documentation link) method which can be used in this scenario.
The method receives a String argument to parse along with a String pattern argument and the requested Location of the time. Here is the method signature below.
def self.parse(time : String, pattern : String, location : Location) : Time
For your example, we could use the formatter to provide our custom format as %m-%d-%Y, where %m means month MM format, %d means day DD format, and %Y means YYYY format. Finally we use the local Location of the script being run.
For example:
time = Time.parse("04-08-2022", "%m-%d-%Y", Time::Location.local)

What is the main difference between WriteSet, TransferSet and ContractResult in Ride4dApps?

In Ride4dApps, the callable function returns WriteSet, TransferSet or a ContractResult but I still do not get the main difference between them? and who pays fees for this kind of dApps?
TransferSet, It's a keyValue list which defines what outgoing
payments will be made upon your contract invocation.
WriteSet, It's a keyValue list which defines what data will be stored
in contract's account upon your contract invocation(for example the
caller address and balance). So basically it's a list of data entries
that should be recorded to read the dApp state.
ContractResult, It's the combination of WriteSet and TransferSet.
The sender pays fees in WAVES(1 + 4*(the cost of each script involved)) to the miner of the invocation.
Example:
ContractResult(
WriteSet([DataEntry(currentKey, amount)]),
TransferSet([ContractTransfer(i.caller, amount, unit)])
)
Where:
DataEntry (key : String, value : String | Binary | Integer | Boolean).
i.caller is the caller address.

How to sign a transaction in multichain?

I want to know the sequence of API commands or cli commands to sign a transaction in multichain ?
Here is the list of commands you have to call in order to sign a transaction in multichain.
SO first in order to sign a transaction you need to have an address so to generate address on multichain node. you have to call :
1.) createkeypairs- it will give you three key value pairs : a) publick key b) public address 3.) privkey
Then you have to import this address to the node using :
2.) importaddress ( address )
After importing the address you have to call createrawsendfrom which will give you a hex.
3.) createrawsendfrom
After createrawsendfrom you have to call signrawtransaction and pass the hex obtained from createrawsendfrom.
4.) signrawtransaction ( hex obtained from createrawsenfrom)
After signrawtransaction, call sendrawtransaction and pass the hex obtained from signrawtransaction and it will give you the transaction succcesful and txid. Your transaction can be seen on explorer after this.
5.) sendrawtransaction ( hex obtained from signrawtransaction)

Converting binary value to string and back to binary?

I have rowversion value that comes from Database in binary format. I need to convert that value to string in order to pass in my front-end code. Then when user submits data back to the server I need to convert that string back to binary. Here is example of my data:
Binary 00000010586
Above output is what I see when my query result returns value. Then I tried this:
Encoded value looks like this: iV
Then I tried to decode value back and this is what I have used:
#charsetDecode( local.encodedVal, "utf-8" )#
Then I got this error message: ByteArray objects cannot be converted to strings.
In my database row version column has timestamp type. When query returns that value it's represented as binary in ColdFusion. I use this column as unique id for each row set in my table. Is there a way to handle this conversion in CldFusion adn what would be the best approach?
Your working with binary data, and not with string encodings. You will need to use binaryEncoded and binaryDecode to send your data as a string and convert it back to binary.
The following example converts some binary data into 2 string representations and converts them back into the same byte array with binaryDecodein the dump.
<cfscript>
binaryData = toBinary("SomeBinaryData++");
hexEncoded = binaryEncode(binaryData, "hex");
base64Encoded = binaryEncode(binaryData, "base64");
writeDump([
binaryData,
hexEncoded,
base64Encoded,
binaryDecode(hexEncoded, "hex"),
binaryDecode(base64Encoded, "base64")
]);
</cfscript>
Run the example on TryCF.com

MongoDB / MongoEngine: ValidationError at / [ObjectId('53f466e60ffa5927709972e8')] is not a valid ObjectId

How do I get the actual string ID from ObjectId('53f466e60ffa5927709972e8')?
This is the line that causes the error
humans = [humanInstance[0].id]
Update: I did
humans = [str(humanInstance[0].id)]
and now I get
['53f466e60ffa5927709972e8'] is not a valid ObjectId
Why is this not a valid ObjectID, and how do I get one? :/
The good news is '53f466e60ffa5927709972e8' looks like a valid ObjectId string:
a valid ObjectId (12 byte binary or 24 character hex string)
src: PyMongo ObjectId
You can convert to string as you are doing or via:
"%s" % humanInstance[0]
Or to get a list use a comprehension:
["%s" human for human in humanInstance]
However, your error is because it expects humans to be an ObjectId or a convertible to an ObjectId (the string is fine) but you are providing a list!
['53f466e60ffa5927709972e8'] is not a valid ObjectId
Try setting humans = '53f466e60ffa5927709972e8' or changing your Document schema to be a ListField of ObjectIdFields or ReferenceFields