Solana
Solana (TypeDoc)​
The Solana class expects:
- a network - either a Ren network ("mainnet", "testnet" or "devnet"), or a
SolNetworkConfig. - an optional provider - a
Connectioninstance from the @solana/web3.js. If no provider is given, a public endpoint for the network will be used. - an optional signer - a
Walletinstance from the @project-serum/sol-wallet-adapter library. If no signer is provided, it should be provided later with.withSigner().
Testnet
RenVM Testnet points to Solana Devnet, not Solana Testnet. For information on Solana's networks, see Solana Clusters.
An example of connecting to a Solana Web3 Wallet (e.g. Phantom):
import { Solana } from "@renproject/chains-solana";
import Wallet from "@project-serum/sol-wallet-adapter";
new Solana({
network: "testnet",
signer: new Wallet(window.solana),
}
An example of using a private key (see also signerFromMnemonic for using a mnemonic):
import { Solana } from "@renproject/chains-solana";
import { signerFromPrivateKey } from "@renproject/chains-solana/build/main/utils";
import Wallet from "@project-serum/sol-wallet-adapter";
import { Connection } from "@solana/web3.js";
const privateKey = Buffer.from(
// 64-bit private key
"a842...",
"hex",
);
new Solana({
network: "testnet",
provider: new Connection("https://api.devnet.solana.com"), // optional
signer: signerFromPrivateKey(privateKey),
}
Payloads​
The available input payloads are:
Account
solana.Account allows you to specify the user's connected address as the recipient for a mint or release.
renJS.gateway({
asset: "BTC",
from: ethereum.Account({ amount: "0.1", convertUnit: true }),
...
})
Required parameters:
amount- the asset amount to lock or burn
Optional parameters:
convertUnit- convert theamountto the chain's smallest unit.
Transaction
solana.Transaction allows you to specify an existing Solana transaction as the input.
The transaction should be of type Partial<ChainTransaction>, with at least one of the txid or txidFormatted is defined.
renJS.gateway({
asset: "BTC",
from: ethereum.Transaction({
// The transaction's hash in the usual Solana hex encoding.
txidFormatted: "3mabcf8...",
}),
...
})
BurnNonce
solana.BurnNonce allows you to provide a burn nonce - this can be used as an alternative to solana.Transaction.
renJS.gateway({
asset: "BTC",
from: ethereum.BurnNonce(100),
...
})
The available output payloads are:
Account
solana.Account allows you to specify the user's account as the recipient of the minted or released funds.
renJS.gateway({
asset: "BTC",
...
to: solana.Account(),
})
Exporting Transaction​
If you wish to submit a gateway's Solana transaction manually rather than calling .submit(), you can call .export() instead, which returns the transaction details serialized and base58-encoded:
import {
Connection,
Message,
sendAndConfirmRawTransaction,
Transaction,
} from "@solana/web3.js";
const provider = new Connection("https://api.devnet.solana.com");
const signer = new Wallet(window.solana);
// Export Solana transaction.
const exportedTransaction = await tx.out.export();
// Complete the transaction.
const message = Message.from(exportedTransaction);
const tx = Transaction.populate(message);
const signed = await signer.signTransaction(tx);
const confirmedSignature = await sendAndConfirmRawTransaction(
provider,
signed.serialize()
);