Mit Smart Contract interagieren -Teil 2

Published by Mario Oettler on

Last Updated on 7. September 2024 by Mario Oettler

Es ist auch möglich, Zahlungen an einen Smart Contract zu schicken, um eine Funktion ausführen zu lassen.

Dies geschieht, indem dem Funktionsaufruf ein weiterer Parameter hinzugefügt wird.

const options = {value: 10000000000};
const tx = await contractWithSigner.writeText(text, options);

Der Smart Contract muss ebenfalls angepasst werden.

function writeText(string memory _text) payable public{
 require(msg.value >= price;
 text = _text;
}

Aufgabe

Legen Sie in der Variable price einen entsprechenden Mindestpreis fest (z. B. 10000000000 Wei), der beim Ändern des Variableninhalts bezahlt werden muss.

Passen Sie sowohl den Smart Contract als auch den JavaScript-Code entsprechend an und probieren Sie es aus.

Lösung

Smart Contract

Java Script

Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select: