/initWallet
-
GET | POST /initWallet
{ ownerAddress, chainId }
→{ to, data, gas, gasPrice, nonce }
Notice! Usage of this method is optional and recommended for strong exchange setup
POST Data:
{
"chainId": 1,
"ownerAddress": "**0x1234…1234**",
"contractType" : "payment"
}where
-
chainId - Number of EVM chain
-
ownerAddress - Address of Wallet Owner
-
contractType - check contract types page for more information
How to get chainId:
ChainId you can get from https://chainlist.org
How to get ownerAddress:
You can use
[web3.eth.accounts.create()](https://web3js.readthedocs.io/en/v1.10.0/web3-eth-accounts.html)
of to generate something like this{
address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}Response:
{
"nonce" : 1,
"gas" : 210000,
"gasPrice" : 50000
"data" : "0x2df....Adsd"
"to" : "0x123...123"
}Basically, this JSON describes the transaction which needs to be signed with Private Key of
ownerAddress
passed aboveThis is exact model required by javascript method https://web3js.readthedocs.io/en/v1.2.11/web3-eth-accounts.html#eth-accounts-signtransaction but you free to use any other language to build and sign the transaction from this data.
Examples on different programming languages:
- Javascript
- Go
- Ruby
- Rust
//from previous response
const rawTransaction = {
"nonce" : 1,
"gas" : 210000,
"gasPrice" : 50000
"data" : "0x2df....Adsd"
"to" : "0x123...123"
}
web3.eth.accounts.signTransaction(rawTransaction, privateKey)
.then(signedTx => {
console.log('Signed Transaction:', signedTx.rawTransaction);
})
.catch(err => {
console.error('Error signing transaction:', err);
});package main
import (
"fmt"
"log"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
// Define the raw transaction
rawTransaction := types.NewTransaction(
1, // nonce
common.HexToAddress("0x123...123"), // to
nil, // value (optional)
210000, // gas limit
big.NewInt(50000), // gas price
hexutil.MustDecode("0x2df....Adsd"), // data
)
// Define the private key
privateKey, err := crypto.HexToECDSA("0x123...123")
if err != nil {
log.Fatal(err)
}
// Sign the transaction
signedTx, err := types.SignTx(rawTransaction, types.NewEIP155Signer(nil), privateKey)
if err != nil {
log.Fatal(err)
}
// Get the raw signed transaction
rawSignedTx := signedTx.MarshalJSON()
fmt.Println("Signed Transaction: ", string(rawSignedTx))
}require 'ethereum'
# Define the raw transaction
raw_transaction = {
nonce: 1,
gas: 210000,
gas_price: 50000,
data: "0x2df...Adsd",
to: "0x123...123"
}
# Sign the transaction
private_key = Ethereum::Key.new(private_key: 'YOUR_PRIVATE_KEY')
signed_transaction = Ethereum::Transaction.sign_transaction(raw_transaction, private_key)
puts "Signed Transaction: #{signed_transaction.raw_transaction}"use web3::contract::Contract;
use web3::signing::Key;
use web3::types::{TransactionRequest, U256};
use web3::{transports, Web3};
#[tokio::main]
async fn main() {
let transport = transports::Http::new("http://localhost:8545")
.expect("Failed to create transport");
let web3 = Web3::new(transport);
let private_key = "private_key"; // Replace with your private key
let raw_transaction = TransactionRequest {
nonce: Some(U256::from(1)),
gas: Some(210000.into()),
gas_price: Some(50000.into()),
data: Some("0x2df....Adsd".into()),
to: Some("0x123...123".parse().unwrap()),
..Default::default()
};
let signed_tx = web3.accounts()
.sign_transaction(raw_transaction, Key::Private(private_key.into()), None)
.await
.expect("Failed to sign transaction");
println!("Signed Transaction: {}", signed_tx.raw_transaction);
}As result you need to make the rawTx in String, HEX
-