Let's modify our
new_puzzle method a bit, and demonstrate how a smart contract author might use base64-encoded arguments.
In the previous chapter we had a fairly long NEAR CLI command that called the
new_puzzle, providing it the parameters for all the clues. Having these lengthy parameters on the CLI might get cumbersome. There may be issues needing to escape single or double quotes, and each operating system may wish for a different format on the Terminal or Command Prompt.
We're going to send all the arguments as a base64-encoded string, and make this a bit simpler. For this, we're going to use
Base64VecU8 from the SDK.
Base64VecU8 is great for binary payloads
What we're doing makes sense, but it's worth noting that it's perhaps more common to use
Base64VecU8 when sending binary parameters.
Read more about it here.
First we'll set up a struct for the arguments we're expecting:
Then we modify our
new_puzzle method like so:
We can take our original arguments and base64 encode them, using whatever method you prefer. There are plenty of online tool, Terminal commands, and open source applications like Boop.
We'll copy this:
and base64 encode it:
Now we can build and run the new crossword puzzle contract as we have before:
Back at the project root (not in the
contract directory) we can run our app and see the new crossword puzzle:
Once you understand cross-contract calls and callbacks and where the logic should go, you can build just about anything on NEAR.
This might be a good time for a reminder that this crossword puzzle, which checks permissions to methods based on a public key, is a bit unusual. It's more common to have simple collections or mappings for allowed users, or utilize the
owner_id field we set up. The account and access key system in NEAR is quite powerful, and hopefully this tutorial helps stretch the limits of what's possible, like the seamless onboarding we have with the crossword puzzle.
Again, the final code for this chapter: