mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-24 21:55:52 +00:00
Add sample python code for DIDs and Price Oracles (#2932)
* Create create_price_oracle.py * Create README.md * Update README.md * Update create_price_oracle.py * Create delete_price_oracle.py * Update delete_price_oracle.py * Create account_price_oracles.py * Create did_set.py * Create did_delete.py * Create account_did.py * Create requirements.txt * Create README.md * Create requirements.txt * Update README.md * Update README.md * Create README.md * Create README.md * Update did_set.py * Update did_set.py * Update did_set.py * Update did_delete.py * Update README.md * Update create_price_oracle.py * Update did_set.py * Update README.md * Update README.md * Update delete_price_oracle.py * Update README.md
This commit is contained in:
57
_code-samples/did/py/did_set.py
Normal file
57
_code-samples/did/py/did_set.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# This allows you to create or update a DID
|
||||
from xrpl.models import DIDSet
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import generate_faucet_wallet
|
||||
from xrpl.transaction import submit_and_wait
|
||||
from xrpl.utils import str_to_hex
|
||||
|
||||
|
||||
# connect to the xrpl via a client
|
||||
print("Connecting to client")
|
||||
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
|
||||
print("connected!!!")
|
||||
|
||||
|
||||
# define/generate a wallet / account
|
||||
account_did_creator = generate_faucet_wallet(client)
|
||||
|
||||
print("⭐successfully generated wallet")
|
||||
print("here's your seed. You'll need it to modify and delete the DID set by this account/wallet")
|
||||
# it is not good practise to expose your seed.
|
||||
print(f"seed: {account_did_creator.seed}")
|
||||
|
||||
|
||||
# define the document associated with the DID
|
||||
document = "did:example:123#public-key-0"
|
||||
|
||||
# define the data associated with the DID
|
||||
# The public attestations of identity credentials associated with the DID.
|
||||
data = "did:example:123#key-1"
|
||||
|
||||
# define the uri associated with the DID
|
||||
# The Universal Resource Identifier associated with the DID.
|
||||
uri = "https://example.did.com/123"
|
||||
|
||||
|
||||
# build DID SET transaction
|
||||
# str_to_hex() converts the inputted string to blockchain understandable hexadecimal
|
||||
did_set_txn = DIDSet(
|
||||
account=account_did_creator.address,
|
||||
did_document=str_to_hex(document),
|
||||
data=str_to_hex(data),
|
||||
uri=str_to_hex(uri),
|
||||
)
|
||||
|
||||
|
||||
# sign, submit the transaction and wait for the response
|
||||
print("siging and submitting the transaction, awaiting a response")
|
||||
did_set_txn_response = submit_and_wait(
|
||||
transaction=did_set_txn, client=client, wallet=account_did_creator
|
||||
)
|
||||
|
||||
# Parse response for result
|
||||
did_set_txn_result = did_set_txn_response.result
|
||||
|
||||
# Print result and transaction hash
|
||||
print(did_set_txn_result["meta"]["TransactionResult"])
|
||||
print(did_set_txn_result["hash"])
|
||||
Reference in New Issue
Block a user