Solidity x Ralph - AlphWallet
Exploration of Ralph, new smart contract language powered by Alephium

Search for a command to run...
Exploration of Ralph, new smart contract language powered by Alephium

No comments yet. Be the first to comment.
In this series, we are going to explore the difference between Ralph, smart contract language developed by Alephium and Solidity developed by Ethereum
Ralph is the smart contract programming language for the Alephium blockchain, which focuses on three goals: security, simplicity and efficiency. Alephium follows the following principles when designing Ralph: Make the smart contract DSL as simple as...
Checkpoint SMB (Spark) offers built-in OpenTelemetry support, enabling users to export logs to OpenTelemetry-compatible servers for monitoring and visualization in tools like Grafana. Source: https://www.dash0.com/guides/opentelemetry-collector Impo...

In this post we’re exploring different ways to fetch live onchain data from different AAVE (V3) markets and display useful information in widgets on iOS. Why ? Aave V3 is a decentralized, non-custodial liquidity protocol that enables users to supply ...

Detecting impersonators on Telegram is a time-consuming task where you’re always one step behind — so why not automate it?

Flash loans have become one of the most debated mechanisms in the DeFi space. While they enable advanced trading strategies such as arbitrage and liquidation, they also create opportunities for exploits and market manipulation. In this article, we wi...

In this new article in our "Building On Alephium" series, we present how we developed the decentralized application "TokenFurnace" on Alephium.

In this article, we're using 0xNekr's X thread which explains how to write a smart contract that emulates a wallet, in Ralph, a smart contract language developed by Alephium.
0You can find his detailed article here: https://explorations-blockchain.com/2023/10/06/conception-dun-contrat-wallet-un-contrat-pour-gerer-vos-ethers/
Please note that this code is not intended for production use.
First, we'll define the contract fields (state), including the owner of the "wallet" and the balance. The balance will represent the current amount of $ALPH. To save on gas fees, we'll use a variable to track the $ALPH balance instead of tokenRemaining!().

Next, we'll initialize the smart contract, but before that, we need to define the possible errors. The only error here is "InvalidCaller," which occurs if someone other than the owner tries to call the "withdraw()" function (explained later).

Now, things get interesting. Alephium uses annotations to enhance the security of assets (such as ALPH or other tokens) within the contract:
"assetsInContract" allows us to use the assets, specifically ALPH in this case.
"updateFields" is used as we update the contract state, specifically the balance.
"checkExternalCaller" is essential to ensure that only the owner can withdraw funds
And as we saw we are checking that the person who called the address is the owner. If not the error codes defined before will be used

The "receive" function enables the wallet owner to receive $ALPH. In this case, we also use annotations, although we don't check the caller because anyone can send $ALPH to this address.
The "PreapprovedAssets" annotation signifies that this smart contract utilizes assets, particularly ALPH. It's worth noting that this annotation introduces the concept of the Asset Permission System (APS), which will be explained in a future thread.

This smart contract is quite straightforward and serves to illustrate the similarities and differences between Ralph and Solidity. You can find a side-by-side comparison on our Github: https://github.com/notrustverify/solidity-ralph/blob/main/alphWallet/README.md#side-by-side
Special thanks to 0xNekr and their thread for the inspiration: https://twitter.com/0xNekr/status/1711766545959903526.
If you want to know more about Ralph and Alephium your journey will start here
Stay tuned for our next article, which will dive into APS and TxScript
For those who want to read the code, it's hosted on Github: https://github.com/notrustverify/solidity-ralph/tree/main/alphWallet
Sources: