Merge pull request #2305 from XRPLF/xchain-bridge-docs

XChainBridge Docs
This commit is contained in:
oeggert
2024-01-09 17:09:11 -08:00
committed by GitHub
29 changed files with 2303 additions and 8 deletions

View File

@@ -17,6 +17,7 @@ If you don't [run your own `rippled` server](install-rippled.html), you can use
| Ripple[¹][] | Testnet | `https://s.altnet.rippletest.net:51234/` | `wss://s.altnet.rippletest.net:51233/` | Testnet public server |
| XRPL Labs | Testnet | `https://testnet.xrpl-labs.com/` | `wss://testnet.xrpl-labs.com/` | Testnet public server with CORS support |
| Ripple[¹][] | Devnet | `https://s.devnet.rippletest.net:51234/` | `wss://s.devnet.rippletest.net:51233/` | Devnet public server |
| Ripple[¹][] | Sidechain-Devnet | `https://sidechain-net2.devnet.rippletest.net:51234/` | `wss://sidechain-net2.devnet.rippletest.net:51233/` | Sidechain Devnet to test cross-chain bridge features. Devnet serves as the locking chain while this sidechain serves as the issuing chain. |
| XRPL Labs | Xahau Testnet | `https://xahau-test.net/` | `wss://xahau-test.net/` | [Hooks-enabled](https://hooks.xrpl.org/) Xahau Testnet |
[Network]: parallel-networks.html

View File

@@ -0,0 +1,8 @@
---
html: use-xrpl-sidechains.html
parent: tasks.html
template: pagetype-category.html.jinja
---
# Use XRPL Sidechains
Bridge XRP and tokens from _Mainnet_ to XRPL sidechains.

View File

@@ -0,0 +1,168 @@
---
html: set-up-iou-iou-bridge.html
parent: use-xrpl-sidechains.html
blurb: Steps to set up an IOU-IOU bridge.
labels:
- Interoperability
---
# Set Up an IOU-IOU Bridge
_(Requires the [XChainBridge amendment][] :not_enabled:)_
Setting up an IOU-IOU bridge enables you to move tokens between chains.
**Note**: The code samples on this page illustrate how to bridge a hypotethical "TST" token from *Devnet* to *Sidechain-Devnet*, using a supported [client library](client-libraries.html) to query and submit transactions.
## Prerequisites
- An XRP-XRP bridge must be set up between the locking and issuing chain.
- Ensure the witnesses' transaction submission accounts are funded on the locking and issuing chains.
- Set up an issuer on the issuing chain to mint and burn a wrapped version of the token you want to bridge. See: [Issue a Fungible Token](issue-a-fungible-token.html)
## Steps
### 1. Connect to the locking chain (Devnet) and issuing chain (Sidechain-Devnet).
```javascript
const xrpl = require('xrpl')
const WS_URL_lockingchain = 'wss://s.devnet.rippletest.net:51233/' // Locking chain
const WS_URL_issuingchain = 'wss://sidechain-net2.devnet.rippletest.net:51233/' // Issuing chain
// Define the XChainBridge, using the "TST" token.
const xchainbridge = {
"LockingChainDoor": "rn895gh1MHnnAgL4hR9q464PJSFiYwQYcV",
"LockingChainIssue": {
"currency": "TST",
"issuer": "rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd"
},
"IssuingChainDoor": "ra1MsW5s6Qg4NXUAJVKw8f21ZghSYG1DQw", // Use the account issuing the wrapped token
"IssuingChainIssue": {
"currency": "TST",
"issuer": "ra1MsW5s6Qg4NXUAJVKw8f21ZghSYG1DQw"
}
}
async function main() {
// Define the network clients.
const client_lockingchain = new xrpl.Client(WS_URL_lockingchain)
await client_lockingchain.connect()
const client_issuingchain = new xrpl.Client(WS_URL_issuingchain)
await client_issuingchain.connect()
// ... custom code goes here
// Disconnect when done (If you omit this, Node.js won't end the process)
await client_lockingchain.disconnect()
await client_issuingchain.disconnect()
}
main()
```
### 2. Submit an `XChainCreateBridge` transaction from the door account on the locking chain.
Don't include a `MinAccountCreateAmount` value.
```javascript
const wallet_lockingchain = xrpl.Wallet.fromSeed('s████████████████████████████') // Locking chain door account
const xchaincreatebridge_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "XChainCreateBridge",
"Account": wallet_lockingchain.address,
"XChainBridge": xchainbridge,
"SignatureReward": 200
}, {autofill: true, wallet: wallet_lockingchain})
```
### 3. Submit a `SignerListSet` transaction from the door account on the locking chain.
```javascript
const signerlistset_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "SignerListSet",
"Account": wallet_lockingchain.address,
"Fee": "12",
"SignerQuorum": 2,
// Use the witness servers' submitting accounts on the locking chain.
"SignerEntries": [
{
"SignerEntry": {
"Account": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
"SignerWeight": 1
}
},
{
"SignerEntry": {
"Account": "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
"SignerWeight": 1
}
}
]
}, {autofill: true, wallet: wallet_lockingchain})
```
### 4. Disable the master key on the locking chain's door account with an `AccountSet` transaction.
```javascript
const disablekey_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "AccountSet",
"Account": wallet_lockingchain.address,
"SetFlag": 4
}, {autofill: true, wallet: wallet_lockingchain})
```
### 5. Submit an `XChainCreateBridge` transaction from the door account on the issuing chain.
Don't include a `MinAccountCreateAmount` value.
```javascript
const wallet_issuingchain = xrpl.Wallet.fromSeed('s████████████████████████████') // The account issuing the wrapped token
const xchaincreatebridge_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "XChainCreateBridge",
"Account": wallet_issuingchain.address,
"XChainBridge": xchainbridge,
"SignatureReward": 200
}, {autofill: true, wallet: wallet_issuingchain})
```
### 6. Submit a `SignerListSet` transaction from the door account on the issuing chain.
```javascript
const signerlistset_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "SignerListSet",
"Account": wallet_issuingchain.address,
"Fee": "12",
"SignerQuorum": 2,
// Use the witness servers' submitting accounts on the issuing chain.
"SignerEntries": [
{
"SignerEntry": {
"Account": "rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo",
"SignerWeight": 1
}
},
{
"SignerEntry": {
"Account": "rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd",
"SignerWeight": 1
}
}
]
}, {autofill: true, wallet: wallet_issuingchain})
```
### 7. Disable the master key on the issuing chain's door account with an `AccountSet` transaction.
```javascript
const disablekey_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "AccountSet",
"Account": wallet_issuingchain.address,
"SetFlag": 4
}, {autofill: true, wallet: wallet_issuingchain})
```
<!--{# common link defs #}-->
{% include '_snippets/rippled-api-links.md' %}
{% include '_snippets/tx-type-links.md' %}
{% include '_snippets/rippled_versions.md' %}

View File

@@ -0,0 +1,234 @@
---
html: set-up-xrp-xrp-bridge.html
parent: use-xrpl-sidechains.html
blurb: Steps to create an XRP-XRP bridge with a new sidechain.
labels:
- Interoperability
---
# Set Up an XRP-XRP Bridge
_(Requires the [XChainBridge amendment][] :not_enabled:)_
Setting up an XRP-XRP bridge enables you to move XRP between chains. The set up requires using the genesis account on the issuing chain as a door account to submit attestations and create transaction submission accounts for witnesses.
**Note**: The code samples on this page illustrate how a bridge was set up between *Devnet* and *Sidechain-Devnet*, using a supported [client library](client-libraries.html) to query and submit transactions. This bridge is already created, so the process can't be reproduced on these networks.
## Prerequisites
- The issuing chain is set up and active. Validators must be running and successfully closing ledgers.
- The witnesses' accounts on the locking chain are funded, so they can submit transactions.
- A door account for the bridge exists on the locking chain.
## Steps
### 1. Connect to the locking chain (Devnet) and issuing chain (Sidechain-Devnet).
```javascript
const xrpl = require('xrpl')
const WS_URL_lockingchain = 'wss://s.devnet.rippletest.net:51233/' // Locking chain
const WS_URL_issuingchain = 'wss://sidechain-net2.devnet.rippletest.net:51233/' // Issuing chain
// Define the XChainBridge
const xchainbridge = {
"LockingChainDoor": "rnQAXXWoFNN6PEqwqsdTngCtFPCrmfuqFJ", // Locking chain door account
"LockingChainIssue": {
"currency": "XRP"
},
"IssuingChainDoor": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", // Use the genesis address hardcoded in rippled
"IssuingChainIssue": {
"currency": "XRP"
}
}
async function main() {
// Define the network clients.
const client_lockingchain = new xrpl.Client(WS_URL_lockingchain)
await client_lockingchain.connect()
const client_issuingchain = new xrpl.Client(WS_URL_issuingchain)
await client_issuingchain.connect()
// ... custom code goes here
// Disconnect when done (If you omit this, Node.js won't end the process)
await client_lockingchain.disconnect()
await client_issuingchain.disconnect()
}
main()
```
### 2. Submit an `XChainCreateBridge` transaction from the door account on the locking chain.
```javascript
const wallet_lockingchain = xrpl.Wallet.fromSeed('s████████████████████████████') // Locking chain door account
const xchaincreatebridge_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "XChainCreateBridge",
"Account": wallet_lockingchain.address,
"XChainBridge": xchainbridge,
"SignatureReward": 200,
"MinAccountCreateAmount": 1000000 // This value should at least be equal to the account reserve on the issuing chain.
}, {autofill: true, wallet: wallet_lockingchain})
```
### 3. Submit a `SignerListSet` transaction from the door account on the locking chain.
```javascript
const signerlistset_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "SignerListSet",
"Account": wallet_lockingchain.address,
"Fee": "12",
"SignerQuorum": 2,
// Use the witness servers' submitting accounts on the locking chain.
"SignerEntries": [
{
"SignerEntry": {
"Account": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
"SignerWeight": 1
}
},
{
"SignerEntry": {
"Account": "rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v",
"SignerWeight": 1
}
}
]
}, {autofill: true, wallet: wallet_lockingchain})
```
### 4. Disable the master key on the locking chain's door account with an `AccountSet` transaction.
```javascript
const disablekey_lockingchain = await client_lockingchain.submitAndWait({
"TransactionType": "AccountSet",
"Account": wallet_lockingchain.address,
"SetFlag": 4
}, {autofill: true, wallet: wallet_lockingchain})
```
### 5. Submit an `XChainCreateBridge` transaction from the genesis account on the issuing chain.
```javascript
const wallet_issuingchain = xrpl.Wallet.fromSeed('snoPBrXtMeMyMHUVTgbuqAfg1SUTb') // Use the genesis secret hardcoded in rippled.
const xchaincreatebridge_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "XChainCreateBridge",
"Account": wallet_issuingchain.address,
"XChainBridge": xchainbridge,
"SignatureReward": 200,
"MinAccountCreateAmount": 1000000
}, {autofill: true, wallet: wallet_issuingchain})
```
### 6. Submit `XChainAccountCreateCommit` transactions from the witnesses' locking chain accounts to create corresponding accounts on the issuing chain.
```javascript
const wallet_witness_1 = xrpl.Wallet.fromSeed('s████████████████████████████') // Witness server 1 from `SignerListSet`: rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW
const wallet_witness_2 = xrpl.Wallet.fromSeed('s████████████████████████████') // Witness server 2 from `SignerListSet`: rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v
const xchainaccountcreatecommit_witness_1 = await client_lockingchain.submitAndWait({
"TransactionType": "XChainAccountCreateCommit",
"Account": wallet_witness_1.address,
"Destination": "rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo", // The account to create and fund for witness 1 on the issuing chain.
"TransactionType": "XChainAccountCreateCommit",
"Amount": "20000000",
"SignatureReward": "100",
"XChainBridge": xchainbridge
}, {autofill: true, wallet: wallet_witness_1})
const xchainaccountcreatecommit_witness_2 = await client_lockingchain.submitAndWait({
"TransactionType": "XChainAccountCreateCommit",
"Account": wallet_witness_2.address,
"Destination": "rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd", // The account to create and fund for witness 2 on the issuing chain.
"TransactionType": "XChainAccountCreateCommit",
"Amount": "20000000",
"SignatureReward": "100",
"XChainBridge": xchainbridged
}, {autofill: true, wallet: wallet_witness_1})
```
### 7. Submit attestations for each `XChainAccountCreateCommit` transaction.
Use the `XChainAddAccountCreateAttestation` transaction to submit each attestation on the issuing chain. Sign these transactions with the genesis account on the issuing chain.
```javascript
// Witness 1 attestation
const xchainaddaccountcreateattestation_witness_1 = await client_issuingchain.submitAndWait({
"TransactionType": "XChainAddAccountCreateAttestation",
"Account": wallet_issuingchain.address,
"OtherChainSource": wallet_witness_1.address,
"Destination": "rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo",
"Amount": "2000000000",
"PublicKey": wallet_witness_1.publicKey,
"Signature": xchainaccountcreatecommit_witness_1.result.TxnSignature,
"WasLockingChainSend": 1,
"AttestationRewardAccount": "rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo",
"AttestationSignerAccount": wallet_witness_1.address,
"XChainAccountCreateCount": "1",
"SignatureReward": "204",
"XChainBridge": xchainbridge,
"Fee": "20"
}, {autofill: true, wallet: wallet_issuingchain})
// Witness 2 attestation
const xchainaddaccountcreateattestation_witness_2 = await client_issuingchain.submitAndWait({
"TransactionType": "XChainAddAccountCreateAttestation",
"Account": wallet_issuingchain.address,
"OtherChainSource": wallet_witness_2.address,
"Destination": "rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd",
"Amount": "2000000000",
"PublicKey": wallet_witness_2.publicKey,
"Signature": xchainaccountcreatecommit_witness_2.result.TxnSignature,
"WasLockingChainSend": 1,
"AttestationRewardAccount": "rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd",
"AttestationSignerAccount": wallet_witness_2.address,
"XChainAccountCreateCount": "1",
"SignatureReward": "204",
"XChainBridge": xchainbridge,
"Fee": "20"
}, {autofill: true, wallet: wallet_issuingchain})
```
### 8. Submit a `SignerListSet` transaction from the genesis account on the issuing chain.
```javascript
const signerlistset_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "SignerListSet",
"Account": wallet_issuingchain.address,
"Fee": "12",
"SignerQuorum": 2,
// Use the witness servers' submitting accounts on the issuing chain created in step 7
"SignerEntries": [
{
"SignerEntry": {
"Account": "rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo",
"SignerWeight": 1
}
},
{
"SignerEntry": {
"Account": "rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd",
"SignerWeight": 1
}
}
]
}, {autofill: true, wallet: wallet_issuingchain})
```
### 9. Disable the master key on the issuing chain's genesis account with an `AccountSet` transaction.
```javascript
const disablekey_issuingchain = await client_issuingchain.submitAndWait({
"TransactionType": "AccountSet",
"Account": wallet_issuingchain.address,
"SetFlag": 4
}, {autofill: true, wallet: wallet_issuingchain})
```
<!--{# common link defs #}-->
{% include '_snippets/rippled-api-links.md' %}
{% include '_snippets/tx-type-links.md' %}
{% include '_snippets/rippled_versions.md' %}

View File

@@ -0,0 +1,136 @@
---
html: submit-cross-chain-transactions.html
parent: use-xrpl-sidechains.html
blurb: Steps to submit a cross-chain transaction, using a bridge.
labels:
- Interoperability
---
# Submit Cross-chain Transactions
_(Requires the [XChainBridge amendment][] :not_enabled:)_
This tutorial explains how to create a test account on a locking chain (_Devent_), and transfer XRP to an issuing chain (_Sidechain-Devnet_), using a supported [client library](client-libraries.html) to query and submit transactions. Witness servers are already set up to monitor the XRP-XRP bridge and submit attestations.
## Prerequisites
- The locking and issuing chains are both up and running.
- The witness servers are up and running.
- Set up the XRP-XRP bridge.
## Steps
### 1. Connect to the locking chain (Devnet) and issuing chain (Sidechain-Devnet).
```javascript
const xrpl = require('xrpl')
const WS_URL_lockingchain = 'wss://s.devnet.rippletest.net:51233/' // Locking chain
const WS_URL_issuingchain = 'wss://sidechain-net2.devnet.rippletest.net:51233/' // Issuing chain
// Define the XChainBridge
const xchainbridge = {
"LockingChainDoor": "rnQAXXWoFNN6PEqwqsdTngCtFPCrmfuqFJ", // Locking chain door account
"LockingChainIssue": {
"currency": "XRP"
},
"IssuingChainDoor": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", // Use the genesis address hardcoded in rippled
"IssuingChainIssue": {
"currency": "XRP"
}
}
async function main() {
// Define the network clients.
const client_lockingchain = new xrpl.Client(WS_URL_lockingchain)
await client_lockingchain.connect()
const client_issuingchain = new xrpl.Client(WS_URL_issuingchain)
await client_issuingchain.connect()
// ... custom code goes here
// Disconnect when done (If you omit this, Node.js won't end the process)
await client_lockingchain.disconnect()
await client_issuingchain.disconnect()
}
main()
```
### 2. Fund a wallet on Devnet and generate a wallet address for Sidechain-Devnet.
```javascript
// Create a wallet and fund it using the XRP faucet on Devnet.
const wallet_lockingchain = (await client_lockingchain.fundWallet()).wallet
console.log(wallet_lockingchain.address)
// Generate a wallet to create and fund on the issuing chain.
const wallet_issuingchain = await xrpl.Wallet.generate()
console.log(wallet_issuingchain.address)
```
### 3. Submit an `XChainAccountCreateCommit` transaction from the Devnet wallet.
```javascript
const createwallet_issuingchain = await client_lockingchain.submitAndWait({
"TransactionType": "XChainAccountCreateCommit",
"Account": wallet_lockingchain.address,
"Destination": wallet_issuingchain.address,
"XChainBridge": xchainbridge,
"SignatureReward": "100",
"Amount": "5000000000"
}, {autofill: true, wallet: wallet_lockingchain})
```
### 4. Create a claim ID with `XChainCreateClaimID`, using your account on the issuing chain.
```javascript
const createclaim = await client_issuingchain.submitAndWait({
"TransactionType": "XChainCreateClaimID",
"Account": wallet_issuingchain.address,
"OtherChainSource": wallet_lockingchain.address,
"SignatureReward": "100",
"XChainBridge": xchainbridge
}, {autofill: true, wallet: wallet_issuingchain})
```
### 5. Retrieve the claim ID from the transaction metadata.
```javascript
let metadata = createclaim.result.meta.AffectedNodes
let claimnode = null;
for (const item of metadata) {
if (item.CreatedNode && item.CreatedNode.LedgerEntryType === 'XChainOwnedClaimID') {
claimnode = item.CreatedNode
break
}
}
const claimID = claimnode.NewFields.XChainClaimID
```
### 6. Submit an `XChainCommit` transaction with the claim ID, using your account on the locking chain.
If you don't specify an "OtherChainDestination", the account that submitted the `XChainCreateClaimID` transaction needs to submit an `XChainClaim` transaction to claim the funds.
```javascript
const xchaincommit = await client_lockingchain.submitAndWait({
"TransactionType": "XChainCommit",
"Account": wallet_lockingchain.address,
"OtherChainDestination": wallet_issuingchain.address,
"Amount": "10000",
"XChainBridge": xchainbridge,
"XChainClaimID": claimID
}, {autofill: true, wallet: wallet_lockingchain})
```
**Note:** When enough `XChainAddClaimAttestation` signatures are submitted by the witness servers to reach quorum, the funds are released on the issuing chain to the `OtherChainDestination`.
<!--{# common link defs #}-->
{% include '_snippets/rippled-api-links.md' %}
{% include '_snippets/tx-type-links.md' %}
{% include '_snippets/rippled_versions.md' %}