Complete the transaction in index.js
found in the folder Lab-Store-a-File-in-a-Cell-Exercise
by adding code and values as necessary.
The transaction you create should have one or more inputs from address1
, one output to address1
with the data
set to the contents of the file HelloNervos.txt
one change cell back to address1
if necessary, and a TX fee.
- Populate the
txFee
variable with a 0.001 CKByte fee.- Hint: The fee value must be given as a BigInt value expressed in Shannons. There are 100,000,000 Shannons in a CKByte.
- Populate the
hexString
variable with the contents of thefiles/HelloNervos.txt
encoded as a hex string.- Hint: Use the Node.js native functions to read the file to a Buffer, then use
.toString("hex")
to convert it to a hex string.
- Hint: Use the Node.js native functions to read the file to a Buffer, then use
- Populate the
dataSize
variable with the size of the data.- Hint: The size of the data should be in binary format, not hex string format.
- Populate the
outputCapacity1
variable with the minimum amount of CKBytes necessary to create a cell with the data being included.- Hint: Capacity values added to the cell output structure must be in Shannons, and expressed as a hex value. Don't forget to use
intToHex()
andckbytesToShannons()
.
- Hint: Capacity values added to the cell output structure must be in Shannons, and expressed as a hex value. Don't forget to use
- Populate the
output1
variable with the JSON structure for an output cell that is owned byaddress
and has the data fromhexString
.- Hint: You can copy the structure from
output2
to use as a reference.
- Hint: You can copy the structure from
Run your code by opening a terminal to the Lab-Store-a-File-in-a-Cell-Exercise
folder and running node index.js
. If you get stuck you can find the solution in the Lab-Store-a-File-in-a-Cell-Solution
folder.
Once your code successfully executes, the resulting transaction ID will be printed on the screen.