generated from shuding/nextra-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from sei-protocol/feature/for-devs-docs
Feature/for devs docs
- Loading branch information
Showing
90 changed files
with
4,062 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"fee-grants": "Fee Grants", | ||
"account-structure": "Account Structure", | ||
"hardware-wallets": "Hardware Wallets", | ||
"querying-historical-state": "Querying Historical State", | ||
"oracles": "Oracles", | ||
"execute-multiple": "Execute Multiple Transactions", | ||
"hd-path-coin-types": "HD Path & Coin Types", | ||
"proposals": "Proposals", | ||
"evm-rpc-endpoints": "EVM RPC Endpoints", | ||
"interoperability": "Interoperability" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Account Structure | ||
|
||
Both EVM derived (0x) and Sei bech32 derived addresses on Sei are derived from the same public key. Accounts are automatically linked once a transaction is broadcasted and the chain has their public key. This ensures that balances and transactions are reflected consistently across both address formats. | ||
|
||
### How It Works | ||
|
||
**Auto-linking**: | ||
|
||
- When an account broadcasts a transaction, the public key is recorded on-chain. This allows for the automatic linking of EVM and Sei addresses. Balances will be reflected in both address formats once linked. | ||
|
||
**Manual Association**: | ||
|
||
- If the chain does not yet have the public key, users can manually associate their accounts using the `sei_associate` function. This is a gasless function that requires at least 1 wei in their account to execute. More details can be found in the [EVM RPC Endpoints documentation](https://v2.docs.sei.io/evm-rpc-endpoints#sei_associate). | ||
|
||
### Key Points | ||
|
||
- **Different Accounts Before Linking**: Until these accounts are linked, the chain treats the Sei address and EVM address as different accounts with different balances. This means that certain dApps may not be able to access your full balance until the accounts are linked. | ||
- **Public Key Requirement**: The linking won’t happen until the chain has the public key. Using `sei_associate`, users can provide their public key to the chain without any gas fees, as long as they have at least 1 wei in their account. | ||
|
||
### Example | ||
|
||
1. **Broadcast a Transaction**: When you make any transaction from your EVM account, the public key is recorded, and the accounts get linked automatically. | ||
2. **Manual Association Using `sei_associate`**: If the accounts are not linked automatically, you can manually associate them with the following command as long as the account you are trying to associate has at least 1 wei in it: | ||
|
||
``` | ||
seid tx evm associate-address [optional priv key hex] --rpc=<url> --from=<sender> [flags] | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
On the Sei blockchain, you can execute multiple messages in a single transaction, which allows for more complex operations to be performed atomically. This section explains how the transaction structure works and how to add multiple messages, even of different types, in one transaction using both CosmJS and seid. | ||
|
||
## **Transaction Structure** | ||
|
||
A transaction on the Sei blockchain consists of the following main components: | ||
|
||
• **Body**: Contains the list of messages to be executed, memo, timeout height, and extension options. | ||
|
||
• **Auth Info**: Includes signer information and fee details. | ||
|
||
• **Signatures**: Holds the signatures of the signers authorizing the transaction. | ||
|
||
Here’s a general structure of a transaction: | ||
|
||
```tsx | ||
{ | ||
"body": { | ||
"messages": [ | ||
// List of messages | ||
], | ||
"memo": "", | ||
"timeout_height": "0", | ||
"extension_options": [], | ||
"non_critical_extension_options": [] | ||
}, | ||
"auth_info": { | ||
"signer_infos": [], | ||
"fee": { | ||
"amount": [ | ||
{ | ||
"denom": "usei", | ||
"amount": "100000" | ||
} | ||
], | ||
"gas_limit": "200000", | ||
"payer": "", | ||
"granter": "" | ||
} | ||
}, | ||
"signatures": [] | ||
} | ||
``` | ||
|
||
## **Adding Multiple Messages** | ||
|
||
You can add multiple messages of different types in the messages array. Here’s how you can do this using CosmJS and seid. | ||
|
||
### **Using CosmJS** | ||
|
||
```tsx | ||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing"); | ||
const { SigningStargateClient, assertIsBroadcastTxSuccess, coins } = require("@cosmjs/stargate"); | ||
|
||
async function sendTransaction() { | ||
const rpcEndpoint = "https://rpc-endpoint"; | ||
const mnemonic = "your mnemonic"; | ||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "sei" }); | ||
const [account] = await wallet.getAccounts(); | ||
|
||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet); | ||
|
||
const msgSend = { | ||
typeUrl: "/cosmos.bank.v1beta1.MsgSend", | ||
value: { | ||
fromAddress: account.address, | ||
toAddress: "sei1destinationaddress", | ||
amount: coins(1000, "usei"), | ||
}, | ||
}; | ||
|
||
const msgDelegate = { | ||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", | ||
value: { | ||
delegatorAddress: account.address, | ||
validatorAddress: "sei1validatoraddress", | ||
amount: coins(500, "usei"), | ||
}, | ||
}; | ||
|
||
const fee = { | ||
amount: coins(2000, "usei"), | ||
gas: "200000", | ||
}; | ||
|
||
const memo = "Transaction with multiple messages"; | ||
|
||
const result = await client.signAndBroadcast(account.address, [msgSend, msgDelegate], fee, memo); | ||
assertIsBroadcastTxSuccess(result); | ||
console.log(result); | ||
} | ||
|
||
sendTransaction().catch(console.error); | ||
``` | ||
|
||
## Using seid | ||
|
||
To create and broadcast a transaction with multiple messages using seid, follow these steps: | ||
|
||
1. **Define the Unsigned Transaction**: | ||
|
||
Create an unsigned-tx.json file with multiple messages: | ||
|
||
```tsx | ||
{ | ||
"body": { | ||
"messages": [ | ||
{ | ||
"@type": "/cosmos.bank.v1beta1.MsgSend", | ||
"from_address": "sei1sourceaddress", | ||
"to_address": "sei1destinationaddress", | ||
"amount": [ | ||
{ | ||
"denom": "usei", | ||
"amount": "1000" | ||
} | ||
] | ||
}, | ||
{ | ||
"@type": "/cosmos.staking.v1beta1.MsgDelegate", | ||
"delegator_address": "sei1sourceaddress", | ||
"validator_address": "sei1validatoraddress", | ||
"amount": { | ||
"denom": "usei", | ||
"amount": "500" | ||
} | ||
} | ||
], | ||
"memo": "Transaction with multiple messages", | ||
"timeout_height": "0", | ||
"extension_options": [], | ||
"non_critical_extension_options": [] | ||
}, | ||
"auth_info": { | ||
"signer_infos": [], | ||
"fee": { | ||
"amount": [ | ||
{ | ||
"denom": "usei", | ||
"amount": "2000" | ||
} | ||
], | ||
"gas_limit": "200000", | ||
"payer": "", | ||
"granter": "" | ||
} | ||
}, | ||
"signatures": [] | ||
} | ||
``` | ||
|
||
2. **Sign the Transaction**: | ||
|
||
```tsx | ||
seid tx sign unsigned-tx.json --from <your_account> --output-document=signed-tx.json --node <YOUR_RPC_URL> | ||
``` | ||
|
||
3. **Broadcast the Signed Transaction**: | ||
|
||
```tsx | ||
seid tx broadcast signed-tx.json --node <YOUR_RPC_URL> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Fee Grants | ||
|
||
Fee grants allow an account to pay for the transaction fees of another account, which is especially useful for onboarding new users who might not have enough tokens to cover transaction fees. This feature is supported in the Cosmos SDK. | ||
|
||
- **How They Work**: Fee grants can be set up so that one account (the granter) can pay for the transaction fees of another account (the grantee). The granter specifies conditions under which the fees will be paid. | ||
- **Documentation**: Detailed documentation on fee grants can be found in the [Cosmos SDK Fee Grants Documentation](https://docs.cosmos.network/v0.46/modules/feegrant/). | ||
|
||
### Granting | ||
|
||
seid | ||
|
||
`seid tx feegrant grant [granter_key_or_address] [grantee]` | ||
|
||
cosmjs | ||
|
||
```jsx | ||
const { SigningStargateClient, GasPrice } = require("@cosmjs/stargate"); | ||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing"); | ||
|
||
async function grantFeeGrant(rpcEndpoint, granterMnemonic, granteeAddress) { | ||
const granterWallet = await DirectSecp256k1HdWallet.fromMnemonic(granterMnemonic, { prefix: "sei" }); | ||
const [granterAccount] = await granterWallet.getAccounts(); | ||
|
||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, granterWallet, { | ||
gasPrice: GasPrice.fromString("0.025usei"), | ||
}); | ||
|
||
const msg = { | ||
typeUrl: "/cosmos.feegrant.v1beta1.MsgGrantAllowance", | ||
value: { | ||
granter: granterAccount.address, | ||
grantee: granteeAddress, | ||
allowance: { | ||
typeUrl: "/cosmos.feegrant.v1beta1.BasicAllowance", | ||
value: { | ||
spendLimit: [{ denom: "usei", amount: "1000000" }], | ||
expiration: null, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const fee = { | ||
amount: [{ denom: "usei", amount: "5000" }], | ||
gas: "200000", | ||
}; | ||
|
||
const result = await client.signAndBroadcast(granterAccount.address, [msg], fee); | ||
console.log(result); | ||
} | ||
|
||
const rpcEndpoint = "https://rpc-endpoint"; | ||
const granterMnemonic = "your-granter-mnemonic"; | ||
const granteeAddress = "sei1granteeaddress"; | ||
|
||
grantFeeGrant(rpcEndpoint, granterMnemonic, granteeAddress); | ||
``` | ||
|
||
### Revoking | ||
|
||
seid | ||
|
||
`seid tx feegrant revoke [granter] [grantee] [flags]` | ||
|
||
cosmjs | ||
|
||
```jsx | ||
const { SigningStargateClient, GasPrice } = require("@cosmjs/stargate"); | ||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing"); | ||
|
||
async function revokeFeeGrant(rpcEndpoint, granterMnemonic, granteeAddress) { | ||
const granterWallet = await DirectSecp256k1HdWallet.fromMnemonic(granterMnemonic, { prefix: "sei" }); | ||
const [granterAccount] = await granterWallet.getAccounts(); | ||
|
||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, granterWallet, { | ||
gasPrice: GasPrice.fromString("0.025usei"), | ||
}); | ||
|
||
const msg = { | ||
typeUrl: "/cosmos.feegrant.v1beta1.MsgRevokeAllowance", | ||
value: { | ||
granter: granterAccount.address, | ||
grantee: granteeAddress, | ||
}, | ||
}; | ||
|
||
const fee = { | ||
amount: [{ denom: "usei", amount: "5000" }], | ||
gas: "200000", | ||
}; | ||
|
||
const result = await client.signAndBroadcast(granterAccount.address, [msg], fee); | ||
console.log(result); | ||
} | ||
|
||
const rpcEndpoint = "https://rpc-endpoint"; | ||
const granterMnemonic = "your-granter-mnemonic"; | ||
const granteeAddress = "sei1granteeaddress"; | ||
|
||
revokeFeeGrant(rpcEndpoint, granterMnemonic, granteeAddress); | ||
``` |
Oops, something went wrong.